Files
Defame1297andClaude Sonnet 5.5 cf8f4b5bf0
Build / build (pull_request) Successful in 10s
Lint / lint (pull_request) Successful in 17s
Molecule / molecule (pull_request) Successful in 4m43s
feat(roles): add the systemd_hardening and network_interfaces roles
Copied from the environment repository's roles and scrubbed for the
Collection: galaxy namespace mortis, molecule scenarios call the roles by
their FQCN and take their paths from the workflow, README examples use
mortis.kamino.* and documentation addresses, repository-local references
(issue numbers, ADRs, inventory paths) are dropped. network_interfaces
loses its Legacy name guard and the molecule play that tested it: the
guard only protected the in-repo rename, and a new consumer never had the
old names. mock_roles in .ansible-lint lists both FQCNs.

Not verified locally: the molecule scenarios (they run on the
kamino-molecule runner in CI) and ansible-test sanity.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
2026-11-10 15:09:48 +00:00

103 lines
4.4 KiB
YAML

---
# The rendered file, the backup of the legacy body and the single reload. The last play is the
# role's lock-out protection: a failing validation must put the previous file back. It
# changes the container, so it lives here and not in converge.yml, where the idempotence
# run would see it change twice. It works on its own copy of the file.
- name: Verify the converged layout
hosts: all
gather_facts: false
tasks:
- name: Read the interfaces file, its backup and the reload marker
ansible.builtin.slurp:
src: "{{ item }}"
loop:
- /etc/network/interfaces
- /etc/network/interfaces.bak
- /var/tmp/network-interfaces-reload.log
register: network_interfaces_verify_files
- name: The file holds the loopback, the manual interface and both bridges
ansible.builtin.assert:
that:
- lines is contains('iface lo inet loopback')
- lines is contains('iface eno1 inet manual')
- lines is contains('auto vmbr0')
- lines is contains('iface vmbr0 inet static')
- lines is contains(' address 10.0.0.2')
- lines is contains(' netmask 255.255.255.0')
- lines is contains(' gateway 10.0.0.1')
- lines is contains(' bridge_ports eno1')
- lines is contains(' bridge_stp off')
- lines is contains(' bridge_vlan_aware yes')
- lines is contains(' bridge_vids 2-4094')
- lines is contains('auto vmbr1')
- lines is contains('iface vmbr1 inet manual')
- lines is contains(' bridge_ports none')
- lines is contains(' bridge_stp on')
- lines is contains(' bridge_fd 5')
- lines | select('search', 'bridge_fd') | list | length == 1
- lines | select('search', 'bridge_vlan_aware') | list | length == 1
- "'legacy seed' not in content"
quiet: true
vars:
content: "{{ network_interfaces_verify_files.results[0].content | b64decode }}"
lines: "{{ content.split('\n') }}"
- name: The backup is the legacy body and the reload ran once
ansible.builtin.assert:
that:
- "'# legacy seed' in (network_interfaces_verify_files.results[1].content | b64decode)"
- "'vmbr0' not in (network_interfaces_verify_files.results[1].content | b64decode)"
- (network_interfaces_verify_files.results[2].content | b64decode).split('\n') | select | list | length == 1
quiet: true
- name: A failing validation restores the previous file
hosts: all
gather_facts: false
vars:
network_interfaces_file: /etc/network/interfaces.rollback
network_interfaces_backup: /etc/network/interfaces.rollback.bak
network_interfaces_validate_command: /bin/false
# A handler notified by the write is still pending when the block is rescued, and it
# runs at the end of the play, so it must not touch the reload marker.
network_interfaces_apply_command: /bin/true
network_interfaces_layout:
manual: [eno1]
bridges:
- name: vmbr9
tasks:
- name: Read the file before
ansible.builtin.slurp:
src: /etc/network/interfaces.rollback
register: network_interfaces_verify_before
- name: Apply the role with a validation that fails
block:
- name: Include the role
ansible.builtin.include_role:
name: mortis.kamino.network_interfaces
- name: Fail when the invalid configuration was accepted
ansible.builtin.fail:
msg: MOLECULE-ACCEPTED
rescue:
- name: The role reverted and refused
ansible.builtin.assert:
that: "'Previous config restored' in ansible_failed_result.msg | default('')"
quiet: true
- name: Read the file and the backup after
ansible.builtin.slurp:
src: "{{ item }}"
loop:
- /etc/network/interfaces.rollback
- /etc/network/interfaces.rollback.bak
register: network_interfaces_verify_after
- name: The previous file is back and the bad one is gone
ansible.builtin.assert:
that:
- network_interfaces_verify_after.results[0].content == network_interfaces_verify_before.content
- network_interfaces_verify_after.results[1].content == network_interfaces_verify_before.content
- "'vmbr9' not in (network_interfaces_verify_after.results[0].content | b64decode)"
quiet: true