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
This commit was merged in pull request #22.
This commit is contained in:
2024-03-07 01:41:39 +00:00
parent 511ecc510b
commit dff665ba36
20 changed files with 207 additions and 41 deletions

View File

@@ -4,9 +4,9 @@
gather_facts: false
- name: imports and executes the playbook under test
ansible.builtin.import_playbook: >-
theliberatededge.test_linux_containers.launch_linux_container.yml
theliberatededge.test_linux_containers.image_published_locally.yml
vars:
lte_debian_version: bookworm
lte_container_name: '{{ molecule_yml.platforms[0].name }}'
lte_image_name: '{{ molecule_yml.platforms[0].name }}'
lte_container_root_pwd: |-
'{{ lookup("ansible.builtin.env", "LTE_CONTAINER_ROOT_PWD") }}'

View File

@@ -1,18 +1,14 @@
---
- name: Create
- name: Destroy testing resources
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: find current container state
ansible.builtin.command: incus ls {{ item.name }}
register: state
changed_when: false
with_items: '{{ molecule_yml.platforms }}'
- name: stop and remove running containers
ansible.builtin.shell:
cmd: |
incus stop {{ item.name }} && \
incus rm {{ item.name }}
when: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout
- name: Stop and remove the test container
ansible.builtin.include_role:
name: >-
theliberatededge.test_linux_containers.linux_container
vars:
lte_container_state: absent
lte_container_name: '{{ item.name }}-container'
with_items: '{{ molecule_yml.platforms }}'

View File

@@ -2,7 +2,7 @@
dependency:
name: galaxy
platforms:
- name: ${LTE_CONTAINER_NAME}
- name: ${LTE_IMAGE_NAME}
provisioner:
name: ansible
playbooks:

View File

@@ -3,13 +3,17 @@
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 }}
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
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