From 4dcdf45a12f68b3b5fe0ace8b96c98d6f50f61ae Mon Sep 17 00:00:00 2001 From: Emil Date: Wed, 6 Mar 2024 01:48:51 +0100 Subject: [PATCH] Introduces LTE_IMAGE_NAME variable. --- README.md | 28 ++++++++++++++---------- Taskfile.yml | 4 ++-- extensions/molecule/default/converge.yml | 2 +- extensions/molecule/default/destroy.yml | 6 ++--- extensions/molecule/default/molecule.yml | 2 +- playbooks/image_published_locally.yml | 4 +++- 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8d62a98..1636672 100644 --- a/README.md +++ b/README.md @@ -33,23 +33,27 @@ ansible-galaxy collection install -U --force \ ## Run the launch_linux_container 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 -- `lte_container_name` stands for the desired container name that -will be visible when running `incus ls`. +- `lte_image_name` stands for the desired Linux container image. - `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 \ - theliberatededge.test_linux_containers.launch_linux_container \ - -e "lte_container_name= lte_container_root_pwd=" + theliberatededge.test_linux_containers.image_published_locally \ + -e "lte_image_name= lte_container_root_pwd=" ``` Once the playbook finishes execution, you should be able to -connect to the newly launched container as user `root` via -ssh. +launch new containers refering to the newly published image name. + +``` +incus launch +``` ## 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 gather_facts: false -- name: imports and executes the playbook under test +- name: Imports and executes the playbook ansible.builtin.import_playbook: - theliberatededge.test_linux_containers.launch_linux_container.yml + theliberatededge.test_linux_containers.image_publlished_locally.yml vars: lte_debian_version: bookworm - lte_container_name: + lte_image_name: lte_container_root_pwd: ``` diff --git a/Taskfile.yml b/Taskfile.yml index c4fe596..c7a5f74 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -22,9 +22,9 @@ tasks: cmds: - | 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 }} \ molecule test --all vars: - LTE_CONTAINER_NAME: + LTE_IMAGE_NAME: sh: cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1 diff --git a/extensions/molecule/default/converge.yml b/extensions/molecule/default/converge.yml index 9599bee..b894944 100644 --- a/extensions/molecule/default/converge.yml +++ b/extensions/molecule/default/converge.yml @@ -7,6 +7,6 @@ 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") }}' diff --git a/extensions/molecule/default/destroy.yml b/extensions/molecule/default/destroy.yml index d8439ac..a4d9f85 100644 --- a/extensions/molecule/default/destroy.yml +++ b/extensions/molecule/default/destroy.yml @@ -5,14 +5,14 @@ gather_facts: false tasks: - name: find current container state - ansible.builtin.command: incus ls {{ item.name }} + ansible.builtin.command: incus ls "{{ item.name }}-container" 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 }} + incus stop "{{ item.name }}-container" && \ + incus rm "{{ item.name }}-container" when: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout with_items: '{{ molecule_yml.platforms }}' diff --git a/extensions/molecule/default/molecule.yml b/extensions/molecule/default/molecule.yml index 9a40fa3..8b06138 100644 --- a/extensions/molecule/default/molecule.yml +++ b/extensions/molecule/default/molecule.yml @@ -2,7 +2,7 @@ dependency: name: galaxy platforms: - - name: ${LTE_CONTAINER_NAME} + - name: ${LTE_IMAGE_NAME} provisioner: name: ansible playbooks: diff --git a/playbooks/image_published_locally.yml b/playbooks/image_published_locally.yml index 43abcc5..2b84d49 100644 --- a/playbooks/image_published_locally.yml +++ b/playbooks/image_published_locally.yml @@ -2,7 +2,9 @@ - name: Create and publish Linux container image to a local image server hosts: localhost gather_facts: false + vars: + - lte_container_name: '{{ lte_image_name }}-container' tasks: - - name: Create a test container image template + - name: Create a test container ansible.builtin.import_role: name: linux_container