From 9a7a08287abcdf357951806f51ab14427441151e Mon Sep 17 00:00:00 2001 From: Aitor Pazos Date: Thu, 1 Aug 2024 12:46:01 +0100 Subject: [PATCH 1/6] Add os-ubuntu-noble tests --- .../molecule/os-ubuntu-noble/collections.yml | 4 ++++ tests/molecule/os-ubuntu-noble/converge.yml | 12 ++++++++++++ tests/molecule/os-ubuntu-noble/molecule.yml | 19 +++++++++++++++++++ tests/molecule/os-ubuntu-noble/prepare.yml | 18 ++++++++++++++++++ .../molecule/os-ubuntu-noble/requirements.yml | 2 ++ tests/molecule/os-ubuntu-noble/verify.yml | 10 ++++++++++ 6 files changed, 65 insertions(+) create mode 100644 tests/molecule/os-ubuntu-noble/collections.yml create mode 100644 tests/molecule/os-ubuntu-noble/converge.yml create mode 100644 tests/molecule/os-ubuntu-noble/molecule.yml create mode 100644 tests/molecule/os-ubuntu-noble/prepare.yml create mode 100644 tests/molecule/os-ubuntu-noble/requirements.yml create mode 100644 tests/molecule/os-ubuntu-noble/verify.yml diff --git a/tests/molecule/os-ubuntu-noble/collections.yml b/tests/molecule/os-ubuntu-noble/collections.yml new file mode 100644 index 0000000..1b1a38c --- /dev/null +++ b/tests/molecule/os-ubuntu-noble/collections.yml @@ -0,0 +1,4 @@ +--- +collections: + - name: community.crypto + version: ">=2.11.1" diff --git a/tests/molecule/os-ubuntu-noble/converge.yml b/tests/molecule/os-ubuntu-noble/converge.yml new file mode 100644 index 0000000..8d580ce --- /dev/null +++ b/tests/molecule/os-ubuntu-noble/converge.yml @@ -0,0 +1,12 @@ +--- +- name: Converge + hosts: all + + environment: + http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') | default(omit) }}" + https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy') | default(omit) }}" + + tasks: + - name: "Include tests" + ansible.builtin.include_role: + name: "tests" diff --git a/tests/molecule/os-ubuntu-noble/molecule.yml b/tests/molecule/os-ubuntu-noble/molecule.yml new file mode 100644 index 0000000..c9b48d0 --- /dev/null +++ b/tests/molecule/os-ubuntu-noble/molecule.yml @@ -0,0 +1,19 @@ +--- +dependency: + name: galaxy +driver: + name: molecule-qemu +platforms: + - name: ubuntu-noble-amd64 + image_url: https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img + image_checksum: sha256:https://cloud-images.ubuntu.com/noble/current/SHA256SUMS + network_ssh_port: 2222 + - name: ubuntu-noble-arm64 + image_arch: aarch64 + image_url: https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-arm64.img + image_checksum: sha256:https://cloud-images.ubuntu.com/noble/current/SHA256SUMS + network_ssh_port: 2223 +provisioner: + name: ansible +verifier: + name: ansible diff --git a/tests/molecule/os-ubuntu-noble/prepare.yml b/tests/molecule/os-ubuntu-noble/prepare.yml new file mode 100644 index 0000000..ce23c04 --- /dev/null +++ b/tests/molecule/os-ubuntu-noble/prepare.yml @@ -0,0 +1,18 @@ +--- +- name: Prepare + hosts: all + become: true + gather_facts: false + + environment: + http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') | default(omit) }}" + https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy') | default(omit) }}" + + tasks: + - name: Wait for SSH to become available + ansible.builtin.wait_for_connection: + delay: 5 + timeout: 300 + + - name: Gather facts + ansible.builtin.setup: diff --git a/tests/molecule/os-ubuntu-noble/requirements.yml b/tests/molecule/os-ubuntu-noble/requirements.yml new file mode 100644 index 0000000..7265dc5 --- /dev/null +++ b/tests/molecule/os-ubuntu-noble/requirements.yml @@ -0,0 +1,2 @@ +--- +roles: [] diff --git a/tests/molecule/os-ubuntu-noble/verify.yml b/tests/molecule/os-ubuntu-noble/verify.yml new file mode 100644 index 0000000..a5cfa75 --- /dev/null +++ b/tests/molecule/os-ubuntu-noble/verify.yml @@ -0,0 +1,10 @@ +--- +# This is an example playbook to execute Ansible tests. + +- name: Verify + hosts: all + gather_facts: false + tasks: + - name: Example assertion + ansible.builtin.assert: + that: true From 4df2fdff0a906812441b6f2a9b585f875a4f60be Mon Sep 17 00:00:00 2001 From: Aitor Pazos Date: Thu, 1 Aug 2024 12:46:25 +0100 Subject: [PATCH 2/6] Ignore Jetbrains IDE files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4b455ba..f7439bf 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,4 @@ dmypy.json src/molecule_plugins/_version.py .vscode/ +.idea/ From c432f8828f7ee652dddeda881f24e1ca16e6bcf8 Mon Sep 17 00:00:00 2001 From: Aitor Pazos Date: Thu, 1 Aug 2024 13:04:11 +0100 Subject: [PATCH 3/6] Fix user-data.j2 sudo definition Ubuntu noble ships a cloud-init version without this fix: https://github.com/canonical/cloud-init/pull/5418 --- molecule_qemu/playbooks/templates/user-data.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/molecule_qemu/playbooks/templates/user-data.j2 b/molecule_qemu/playbooks/templates/user-data.j2 index a7319d9..2ed42e1 100644 --- a/molecule_qemu/playbooks/templates/user-data.j2 +++ b/molecule_qemu/playbooks/templates/user-data.j2 @@ -16,7 +16,7 @@ users: - wheel {%- endif +%} shell: /bin/bash - sudo: ["ALL=(ALL) NOPASSWD:ALL"] + sudo: "ALL=(ALL) NOPASSWD:ALL" lock_passwd: true ssh_authorized_keys: - {{ ssh_keypair.public_key }} From 26f39092da7287764a77fc8720e59638ffa4bbec Mon Sep 17 00:00:00 2001 From: Aitor Pazos Date: Thu, 1 Aug 2024 13:18:50 +0100 Subject: [PATCH 4/6] Add Ubuntu noble to test-os-ubuntu Makefile target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f1efa1c..de02261 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ test-network: test-network-shared test-network-user ## Test network test-os-debian: test-os-debian-bullseye test-os-debian-bookworm ## Test Debian OS .PHONY: test-os-ubuntu -test-os-ubuntu: test-os-ubuntu-focal test-os-ubuntu-jammy ## Test Ubuntu OS +test-os-ubuntu: test-os-ubuntu-focal test-os-ubuntu-jammy test-os-ubuntu-noble ## Test Ubuntu OS .PHONY: test-os test-os: test-os-debian test-os-ubuntu ## Test OS From 354434ed9dc8dfe31303aae3dd488a9a08f1da38 Mon Sep 17 00:00:00 2001 From: Aitor Pazos Date: Thu, 1 Aug 2024 13:24:54 +0100 Subject: [PATCH 5/6] Wait for cloud-init to complete to reduce the chance of race conditions. --- molecule_qemu/playbooks/create.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 7e262e3..c206629 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -438,3 +438,22 @@ content: "{{ instance_conf | to_json | from_json | to_yaml }}" dest: "{{ molecule_instance_config }}" mode: "0644" + + ### wait for cloud-init to complete ####################################### + - add_host: + name: "{{ item.name }}" + ansible_user: "root" + ansible_become: yes + ansible_ssh_host: "{{ molecule_instances_ipv4[item.name] }}" + ansible_ssh_port: "{{ item.network_ssh_port }}" + ansible_ssh_host_key_checking: no + ansible_ssh_private_key_file: "{{ ssh_keypair.filename }}" + loop: "{{ molecule_instances }}" + loop_control: + label: "{{ item.name }}" + + - name: Wait for Cloud-init to complete + ansible.builtin.command: "cloud-init status --wait" + register: cloud_init_status + delegate_to: "{{ item.name }}" + loop: "{{ molecule_instances }}" From b3691657aa00b490aad80a737996b50f67dad13e Mon Sep 17 00:00:00 2001 From: Aitor Pazos Date: Thu, 1 Aug 2024 14:11:56 +0100 Subject: [PATCH 6/6] Lint fixes --- molecule_qemu/playbooks/create.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index c206629..04c02de 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -440,7 +440,8 @@ mode: "0644" ### wait for cloud-init to complete ####################################### - - add_host: + - name: Add hosts to in-memory inventory for follow-up tasks + ansible.builtin.add_host: name: "{{ item.name }}" ansible_user: "root" ansible_become: yes @@ -455,5 +456,6 @@ - name: Wait for Cloud-init to complete ansible.builtin.command: "cloud-init status --wait" register: cloud_init_status + changed_when: false delegate_to: "{{ item.name }}" loop: "{{ molecule_instances }}"