Skip to content

fix(roles/cloud_init): reload NetworkManager after removing 99-cloud-init.conf - #466

Merged
NavidSassan merged 1 commit into
mainfrom
fix/cloud-init-networkmanager-reload
Oct 23, 2026
Merged

NavidSassan merged 1 commit into
mainfrom
fix/cloud-init-networkmanager-reload

Conversation

@markuslf

Copy link
Copy Markdown
Member

Problem

On Rocky 8 and 9, cloud-init's sysconfig renderer writes dns = none to /etc/NetworkManager/conf.d/99-cloud-init.conf whenever the provider hands out DNS servers (Hetzner does). The cloud_init role removes the file but never reloads NetworkManager, so /etc/resolv.conf stays unmanaged until the next NetworkManager restart or reboot. Rocky 10 lists network-manager before sysconfig in cloud.cfg and does not write the file.

Change

  • roles/cloud_init: removing the file notifies a handler running systemctl try-reload-or-restart NetworkManager.service.
    • ansible.builtin.service with state: reloaded would start a stopped NetworkManager (ansible-core 2.16, systemd_service.py); try-reload-or-restart leaves it alone. NetworkManager has an ExecReload, so this never restarts.
    • A reload re-reads conf.d and re-evaluates the DNS mode without touching connections (NetworkManager 1.56, src/core/dns/nm-dns-manager.c, config_changed_cb).
    • rc 5 (unit not found) is tolerated for hosts without NetworkManager.
  • README: the description of the file was inverted; Tags list the reload as trigger.
  • setup_basic Molecule scenario: prepare.yml recreates the leftover file on every host running NetworkManager and asserts the DNS mode is none; verify.yml asserts it is no longer none.
  • CHANGELOG updated.

Testing

setup_basic on all 8 targets, in two batches (idempotence before verify):

  • Debian 12/13, Ubuntu 22.04/24.04/26.04: converge, idempotence (changed=0) and verify green. NetworkManager does not run there, so the new steps are skipped.
  • Rocky 8/9/10: converge green, handler fires, idempotence changed=0, new assertion green.
  • Negative check: with the previous role code, the new assertion fails on Rocky 8/9/10 (DNS mode stays none).

The remaining verify failures on Rocky are unrelated and come from the linuxfabrik-monitoring-plugins 8.0.0 RPM: a corrupt .pyc breaks about-me on Rocky 9, and AIDE reports rewritten .pyc files on Rocky 8 and 10 (same as noted in #453).

…init.conf

cloud-init's sysconfig renderer writes "dns = none" to
/etc/NetworkManager/conf.d/99-cloud-init.conf. Removing the file had no
effect until the next NetworkManager restart or reboot, so
/etc/resolv.conf stayed unmanaged in the meantime.

The role now reloads NetworkManager via
`systemctl try-reload-or-restart`, which leaves a stopped
NetworkManager alone (ansible.builtin.service with state reloaded
would start it). A reload re-reads conf.d and re-evaluates the DNS
mode without touching connections (NetworkManager 1.56,
src/core/dns/nm-dns-manager.c, config_changed_cb).

The setup_basic scenario recreates the leftover file in prepare.yml
and asserts in verify.yml that NetworkManager's DNS mode is no longer
"none". Verified on Rocky 8, 9 and 10: the assertion fails with the
previous role code and passes with this change; a second run reports
changed=0.
@markuslf
markuslf requested a review from NavidSassan October 21, 2026 14:07
@NavidSassan
NavidSassan merged commit e8482a3 into main Oct 23, 2026
13 checks passed
@NavidSassan
NavidSassan deleted the fix/cloud-init-networkmanager-reload branch October 23, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants