From b9554b1e7f696a66e476729efc2ffc35fb559dab Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Tue, 7 Jan 2025 15:48:02 +0100 Subject: [PATCH] Install role pre-requisite packages Historically we were assuming some subsystems like udev or dbus being part of the core images and never handled their installation. However such subsystems are a hard requirement for role to succeed and networkd to operate correctly. To ensure all required bits in place, we've adding installation of dbus and udev to the role in order to prevent failures on very minimal images Change-Id: Ie77a7064d17e6aef0be16b8a5d9be5cc121b665b --- handlers/main.yml | 11 +++++++++++ tasks/main.yml | 12 ++---------- tests/prepare.yml | 17 +---------------- vars/debian-12.yml | 2 ++ vars/debian.yml | 4 +++- vars/redhat-9.yml | 2 ++ vars/ubuntu-24.yml | 2 ++ 7 files changed, 23 insertions(+), 27 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 635cd72..3bd4c0e 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -13,6 +13,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +- name: Ensure required services are running + ansible.builtin.systemd: + name: "{{ item }}" + state: started + enabled: true + masked: false + with_items: + - dbus + - systemd-udevd + listen: Restart systemd-networkd + - name: Restart networkd systemd: name: "systemd-networkd" diff --git a/tasks/main.yml b/tasks/main.yml index bad2df9..3c69dee 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -96,6 +96,8 @@ until: install_packages is success retries: 3 delay: 2 + notify: + - Restart systemd-networkd - name: Create systemd-networkd directory file: @@ -217,16 +219,6 @@ notify: - Restart systemd-networkd -- name: Enable and start systemd-networkd - systemd: - name: "systemd-networkd" - enabled: "yes" - state: started - when: - - systemd_run_networkd | bool - tags: - - systemd-networkd - - name: Restart systemd_networkd prior to applying sysctl changes meta: flush_handlers diff --git a/tests/prepare.yml b/tests/prepare.yml index 3006ec1..9282a3b 100644 --- a/tests/prepare.yml +++ b/tests/prepare.yml @@ -18,34 +18,19 @@ iproute_package_name: redhat: iproute debian: iproute2 - # NOTE: Packages below are potentially needed outside of molecule as well procps_package_name: redhat: procps-ng debian: procps + # Needed for `restorecon` command selinux_package_name: redhat: policycoreutils debian: '' - udev_package_name: - redhat: systemd-udev - debian: udev install_packages: - "{{ iproute_package_name[ansible_facts['os_family'] | lower] }}" - "{{ procps_package_name[ansible_facts['os_family'] | lower] }}" - "{{ selinux_package_name[ansible_facts['os_family'] | lower] }}" - - "{{ udev_package_name[ansible_facts['os_family'] | lower] }}" - - dbus tasks: - name: Install required packages ansible.builtin.package: name: "{{ install_packages | select() }}" update_cache: "{{ (ansible_facts['os_family'] | lower == 'debian') | ternary(true, omit) }}" - - - name: Ensure required services are running - ansible.builtin.systemd: - name: "{{ item }}" - state: started - enabled: true - masked: false - with_items: - - dbus - - systemd-udevd diff --git a/vars/debian-12.yml b/vars/debian-12.yml index 8ec8d09..0aa38cb 100644 --- a/vars/debian-12.yml +++ b/vars/debian-12.yml @@ -14,7 +14,9 @@ # limitations under the License. _systemd_networkd_distro_packages: + - dbus # Needed for networkctl - "{{ systemd_resolved_available | ternary('systemd-resolved', '') }}" + - udev # Needed for networkd to bring interfaces up _systemd_resolved_available: false diff --git a/vars/debian.yml b/vars/debian.yml index 0a427d9..5dd7530 100644 --- a/vars/debian.yml +++ b/vars/debian.yml @@ -13,7 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -_systemd_networkd_distro_packages: [] +_systemd_networkd_distro_packages: + - dbus # Needed for networkctl + - udev # Needed for networkd to bring interfaces up _systemd_resolved_available: true diff --git a/vars/redhat-9.yml b/vars/redhat-9.yml index 2c28c8b..992b10f 100644 --- a/vars/redhat-9.yml +++ b/vars/redhat-9.yml @@ -14,8 +14,10 @@ # limitations under the License. _systemd_networkd_distro_packages: + - dbus # Needed for networkctl - systemd-networkd - "{{ systemd_resolved_available | ternary('systemd-resolved', '') }}" + - systemd-udev # Needed for networkd to bring interfaces up _systemd_resolved_available: false diff --git a/vars/ubuntu-24.yml b/vars/ubuntu-24.yml index 1a3406f..8243d51 100644 --- a/vars/ubuntu-24.yml +++ b/vars/ubuntu-24.yml @@ -14,7 +14,9 @@ # limitations under the License. _systemd_networkd_distro_packages: + - dbus # Needed for networkctl - "{{ systemd_resolved_available | ternary('systemd-resolved', '') }}" + - udev # Needed for networkd to bring interfaces up _systemd_resolved_available: true