emil dff665ba36 i-8 Implements image creation and publishing in playbook (#22)
# Issue

This PR implements the-liberated-edge/test_linux_containers#8

# Acceptance criteria

- [x] The existing playbook has been amended, so that it creates and publishes container images to an incus server running locally.
- [x] Container image name has been parameterised and provided as an Ansible variable.

Co-authored-by: Emil <emil@theliberatededge.org>
Reviewed-on: #22
2024-03-07 01:41:39 +00:00

38 lines
1.5 KiB
YAML

---
- name: Verify
hosts: localhost
gather_facts: false
tasks:
- name: Launch container based on the newly published image
ansible.builtin.command: |
incus launch {{ item.name }} {{ item.name }}-test-cntr
with_items: '{{ molecule_yml.platforms }}'
- name: find current container state
ansible.builtin.command: incus ls '{{ item.name }}-test-cntr'
register: state
with_items: '{{ molecule_yml.platforms }}'
- name: verify launched container is running
ansible.builtin.assert:
that: state.results[0].rc == 0 and 'RUNNING' in state.results[0].stdout
- name: find container ip address
ansible.builtin.command: incus ls -c=4 -f=compact {{ item.name }}
register: ipv4_raw
with_items: '{{ molecule_yml.platforms }}'
- name: set ipv4 address string as a fact
ansible.builtin.set_fact:
ipv4: '{{ ipv4_raw.results[0].stdout_lines[1] }}'
- name: extract ipv4 address of the linux container
ansible.builtin.set_fact:
ipv4: "{{ ipv4 | regex_search('([0-9]+.[0-9]+.[0-9]+.[0-9]+)') }}"
- name: load root password from environment variable
ansible.builtin.set_fact:
pwd: "{{ lookup('ansible.builtin.env', 'LTE_CONTAINER_ROOT_PWD') }}"
- name: connect via ssh to linux container
ansible.builtin.shell:
cmd: |
sshpass -p{{ pwd }} ssh -o ConnectTimeout=1 root@{{ ipv4 }} exit;
register: ssh
- name: verify ssh connection to linux container
ansible.builtin.assert:
that: ssh.rc == 0