Skip to content

Commit

Permalink
Merge pull request #44 from aitorpazos/wait-for-cloud-init-completion
Browse files Browse the repository at this point in the history
Adjust cloud-init user-data to account for Ubuntu 24.04 bug
  • Loading branch information
andreygubarev authored Oct 28, 2024
2 parents 0641923 + b369165 commit f5a1ee6
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,4 @@ dmypy.json
src/molecule_plugins/_version.py

.vscode/
.idea/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions molecule_qemu/playbooks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,24 @@
content: "{{ instance_conf | to_json | from_json | to_yaml }}"
dest: "{{ molecule_instance_config }}"
mode: "0644"

### wait for cloud-init to complete #######################################
- name: Add hosts to in-memory inventory for follow-up tasks
ansible.builtin.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
changed_when: false
delegate_to: "{{ item.name }}"
loop: "{{ molecule_instances }}"
2 changes: 1 addition & 1 deletion molecule_qemu/playbooks/templates/user-data.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 4 additions & 0 deletions tests/molecule/os-ubuntu-noble/collections.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
collections:
- name: community.crypto
version: ">=2.11.1"
12 changes: 12 additions & 0 deletions tests/molecule/os-ubuntu-noble/converge.yml
Original file line number Diff line number Diff line change
@@ -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"
19 changes: 19 additions & 0 deletions tests/molecule/os-ubuntu-noble/molecule.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions tests/molecule/os-ubuntu-noble/prepare.yml
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 2 additions & 0 deletions tests/molecule/os-ubuntu-noble/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
roles: []
10 changes: 10 additions & 0 deletions tests/molecule/os-ubuntu-noble/verify.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f5a1ee6

Please sign in to comment.