Introduces LTE_IMAGE_NAME variable.

This commit is contained in:
Emil 2024-03-06 01:48:51 +01:00
parent c8878ad28b
commit 4dcdf45a12
6 changed files with 26 additions and 20 deletions

View File

@ -33,23 +33,27 @@ ansible-galaxy collection install -U --force \
## Run the launch_linux_container playbook ## Run the launch_linux_container playbook
Substitute the missing variable valuess and run the playbook Substitute the missing variable valuess and run the playbook
for launching Debian Bookworm linux containers. for creating and publishing Debian Bookworm linux container images
to a locally running incus image server.
Variables Variables
- `lte_container_name` stands for the desired container name that - `lte_image_name` stands for the desired Linux container image.
will be visible when running `incus ls`.
- `lte_container_root_pwd` is the password that will be set for - `lte_container_root_pwd` is the password that will be set for
the `root` user in the container named `lte_container_name`. the `root` user in the containers created out of the `lte_image_name`
Linux container image.
``` ```
LC_ALL=C.UTF-8 ansible-playbook \ LC_ALL=C.UTF-8 ansible-playbook \
theliberatededge.test_linux_containers.launch_linux_container \ theliberatededge.test_linux_containers.image_published_locally \
-e "lte_container_name=<container name> lte_container_root_pwd=<password>" -e "lte_image_name=<image name> lte_container_root_pwd=<password>"
``` ```
Once the playbook finishes execution, you should be able to Once the playbook finishes execution, you should be able to
connect to the newly launched container as user `root` via launch new containers refering to the newly published image name.
ssh.
```
incus launch <image_name> <container_name>
```
## Include playbook or role from the collection ## Include playbook or role from the collection
@ -62,15 +66,15 @@ assign the missing values to the variables first.
``` ```
--- ---
- name: Launch Linux Container - name: Create and publish locally container image
hosts: all hosts: all
gather_facts: false gather_facts: false
- name: imports and executes the playbook under test - name: Imports and executes the playbook
ansible.builtin.import_playbook: ansible.builtin.import_playbook:
theliberatededge.test_linux_containers.launch_linux_container.yml theliberatededge.test_linux_containers.image_publlished_locally.yml
vars: vars:
lte_debian_version: bookworm lte_debian_version: bookworm
lte_container_name: <container name> lte_image_name: <image name>
lte_container_root_pwd: <password> lte_container_root_pwd: <password>
``` ```

View File

@ -22,9 +22,9 @@ tasks:
cmds: cmds:
- | - |
LC_ALL=C.UTF-8 \ LC_ALL=C.UTF-8 \
LTE_CONTAINER_NAME={{ .LTE_CONTAINER_NAME }} \ LTE_IMAGE_NAME={{ .LTE_IMAGE_NAME }} \
LTE_CONTAINER_ROOT_PWD={{ .LTE_CONTAINER_ROOT_PWD }} \ LTE_CONTAINER_ROOT_PWD={{ .LTE_CONTAINER_ROOT_PWD }} \
molecule test --all molecule test --all
vars: vars:
LTE_CONTAINER_NAME: LTE_IMAGE_NAME:
sh: cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1 sh: cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1

View File

@ -7,6 +7,6 @@
theliberatededge.test_linux_containers.image_published_locally.yml theliberatededge.test_linux_containers.image_published_locally.yml
vars: vars:
lte_debian_version: bookworm lte_debian_version: bookworm
lte_container_name: '{{ molecule_yml.platforms[0].name }}' lte_image_name: '{{ molecule_yml.platforms[0].name }}'
lte_container_root_pwd: |- lte_container_root_pwd: |-
'{{ lookup("ansible.builtin.env", "LTE_CONTAINER_ROOT_PWD") }}' '{{ lookup("ansible.builtin.env", "LTE_CONTAINER_ROOT_PWD") }}'

View File

@ -5,14 +5,14 @@
gather_facts: false gather_facts: false
tasks: tasks:
- name: find current container state - name: find current container state
ansible.builtin.command: incus ls {{ item.name }} ansible.builtin.command: incus ls "{{ item.name }}-container"
register: state register: state
changed_when: false changed_when: false
with_items: '{{ molecule_yml.platforms }}' with_items: '{{ molecule_yml.platforms }}'
- name: stop and remove running containers - name: stop and remove running containers
ansible.builtin.shell: ansible.builtin.shell:
cmd: | cmd: |
incus stop {{ item.name }} && \ incus stop "{{ item.name }}-container" && \
incus rm {{ item.name }} incus rm "{{ item.name }}-container"
when: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout when: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout
with_items: '{{ molecule_yml.platforms }}' with_items: '{{ molecule_yml.platforms }}'

View File

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

View File

@ -2,7 +2,9 @@
- name: Create and publish Linux container image to a local image server - name: Create and publish Linux container image to a local image server
hosts: localhost hosts: localhost
gather_facts: false gather_facts: false
vars:
- lte_container_name: '{{ lte_image_name }}-container'
tasks: tasks:
- name: Create a test container image template - name: Create a test container
ansible.builtin.import_role: ansible.builtin.import_role:
name: linux_container name: linux_container