From c05f4b35ea3d5b94299373de46164a46bb7b4edd Mon Sep 17 00:00:00 2001 From: Murat Aybars <39916128+aybarsm@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:47:59 +0100 Subject: [PATCH] Empty commit message --- roles/grub/handlers/main.yml | 4 +-- roles/network_interfaces/handlers/command.yml | 9 +++-- roles/network_interfaces/handlers/main.yml | 2 +- roles/network_interfaces/handlers/service.yml | 2 ++ roles/systemd/defaults/main.yml | 35 +++++++++++++++++++ 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/roles/grub/handlers/main.yml b/roles/grub/handlers/main.yml index 2c6b9ba..d9ca528 100644 --- a/roles/grub/handlers/main.yml +++ b/roles/grub/handlers/main.yml @@ -1,6 +1,6 @@ --- - name: Apply linux_grub changes ansible.builtin.import_tasks: - file: "{{ linux_grub_change_strategy }}.yml" + file: command.yml listen: "linux_grub_apply_changes" - when: linux_grub_change_strategy | default('') == 'command' + when: (linux_grub_change_strategy | default('') == 'command') diff --git a/roles/network_interfaces/handlers/command.yml b/roles/network_interfaces/handlers/command.yml index 9d38e64..e934e66 100644 --- a/roles/network_interfaces/handlers/command.yml +++ b/roles/network_interfaces/handlers/command.yml @@ -2,18 +2,21 @@ - name: Apply command(s) for linux_network_interfaces changes become: true ansible.builtin.command: - argv: "{{ item.argv | default(omit) }}" + # argv: "{{ item.argv | default(omit) }}" chdir: "{{ item.chdir | default(omit) }}" cmd: "{{ item.cmd }}" creates: "{{ item.creates | default(omit) }}" - expand_argument_vars: "{{ item.expand_argument_vars | default(omit) }}" - free_form: "{{ item.free_form | default(omit) }}" + # expand_argument_vars: "{{ item.expand_argument_vars | default(omit) }}" + # free_form: "{{ item.free_form | default(omit) }}" removes: "{{ item.removes | default(omit) }}" stdin: "{{ item.stdin | default(omit) }}" stdin_add_newline: "{{ item.stdin_add_newline | default(omit) }}" strip_empty_ends: "{{ item.strip_empty_ends | default(omit) }}" + changed_when: true loop: "{{ linux_network_interfaces_change | selectattr('cmd', 'defined') }}" register: linux_network_interfaces_apply_changes_command + listen: "linux_network_interfaces_apply_changes_by_command" when: + - linux_network_interfaces_change_strategy | default('') == 'command' - linux_network_interfaces_change | type_debug == 'list' - linux_network_interfaces_change | selectattr('cmd', 'defined') | length > 0 diff --git a/roles/network_interfaces/handlers/main.yml b/roles/network_interfaces/handlers/main.yml index 439f745..ea0650d 100644 --- a/roles/network_interfaces/handlers/main.yml +++ b/roles/network_interfaces/handlers/main.yml @@ -1,6 +1,6 @@ --- - name: Apply linux_network_interfaces changes ansible.builtin.import_tasks: - file: "{{ linux_network_interfaces_change_strategy }}.yml" + file: command.yml listen: "linux_network_interfaces_apply_changes" when: linux_network_interfaces_change_strategy | default('') | in ['command', 'service'] diff --git a/roles/network_interfaces/handlers/service.yml b/roles/network_interfaces/handlers/service.yml index ab64df3..ef05ac8 100644 --- a/roles/network_interfaces/handlers/service.yml +++ b/roles/network_interfaces/handlers/service.yml @@ -12,6 +12,8 @@ use: "{{ item.use | default(omit) }}" loop: "{{ linux_network_interfaces_change | selectattr('name', 'defined') }}" register: linux_network_interfaces_apply_changes_service + listen: "linux_network_interfaces_apply_changes_by_service" when: + - linux_network_interfaces_change_strategy | default('') == 'service' - linux_network_interfaces_change | type_debug == 'list' - linux_network_interfaces_change | selectattr('name', 'defined') | length > 0 diff --git a/roles/systemd/defaults/main.yml b/roles/systemd/defaults/main.yml index 4c1b5ae..cb07b9c 100644 --- a/roles/systemd/defaults/main.yml +++ b/roles/systemd/defaults/main.yml @@ -1,2 +1,37 @@ +--- # Ensures system manager is systemd - ansible_service_mgr == "systemd" linux_systemd_ensure_service_manager: true +linux_manage_systemd_network: false + +linux_systemd_network_apply_changes: false + +linux_systemd_network_backup: true +linux_systemd_network_cleanup: false +linux_systemd_network_cleanup_patterns_use_regex: true + +# Consult: https://manpages.debian.org/bookworm/systemd/systemd.net-naming-scheme.7.en.html +linux_systemd_network_naming_scheme: "v252" + +linux_systemd_network_dir: /etc/systemd/network +linux_systemd_network_template: network.j2 + +linux_systemd_network_default: [] +linux_systemd_network_group: [] +linux_systemd_network_host: [] +# The combination strategy below is highly nested hierarchy compliant and recommended +# linux_systemd_network_host > linux_systemd_network_group > linux_systemd_network_default +linux_systemd_network_all: "{{ (linux_systemd_network_host + linux_systemd_network_group + linux_systemd_network_default) | + selectattr('name', 'defined') | selectattr('name', 'search', '\\.(network|link|netdev)$') | + selectattr('config', 'defined') | unique(attribute='name') }}" + +linux_systemd_network_names: "{{ linux_systemd_network_all | map(attribute='name') }}" +# Escape file names defined in linux_systemd_network_all +linux_systemd_network_cleanup_regex: + - "^({{ linux_systemd_network_names | select('match', '.*\\.link$') | map('replace', '.link', '') | join('|') }})\\.link$" + - "^({{ linux_systemd_network_names | select('match', '.*\\.netdev$') | map('replace', '.netdev', '') | join('|') }})\\.netdev$" + - "^({{ linux_systemd_network_names | select('match', '.*\\.network$') | map('replace', '.network', '') | join('|') }})\\.network$" +# Escape backup files: + - "^.*\\.\\d+\\.\\d{4}-\\d{2}-\\d{2}@\\d{2}:\\d{2}:\\d{2}~$" + +# Join regex expressions +linux_systemd_network_cleanup_patterns: ["(?!{{ linux_systemd_network_cleanup_regex | join('|') }})"]