From 0de26dd85e96491166e7cc1c31e993ab71e2eeeb Mon Sep 17 00:00:00 2001 From: Aaron Guise Date: Wed, 2 Nov 2022 12:07:24 +1300 Subject: [PATCH] Added loop_controls --- tasks/networking.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tasks/networking.yml b/tasks/networking.yml index 4aa397a..8eee7e3 100644 --- a/tasks/networking.yml +++ b/tasks/networking.yml @@ -1,9 +1,9 @@ --- - name: Ensure DNS and SSH common config template: - src: "{{ item.src }}" - dest: "{{ item.dest }}" - mode: "{{ item.mode }}" + src: "{{ network_config.src }}" + dest: "{{ network_config.dest }}" + mode: "{{ network_config.mode }}" backup: yes with_items: - { @@ -14,13 +14,15 @@ } - { src: etc.resolv.conf.j2, dest: /etc/resolv.conf, mode: u+rw, a+r } when: ansible_virtualization_type != "docker" + loop_control: + loop_var: network_config tags: dns - name: Ensure hosts file correct lineinfile: dest: /etc/hosts - regexp: "{{ item.regexp }}" - line: "{{ item.line }}" + regexp: "{{ hosts_config.regexp }}" + line: "{{ hosts_config.line }}" backrefs: yes backup: yes with_items: @@ -48,6 +50,8 @@ regexp: "^{{ ansible_default_ipv4.address }}.*{{ ansible_nodename.split('.')[0] }}$", line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }}.{{ domain }} {{ inventory_hostname }}", } + loop_control: + loop_var: hosts_config when: ansible_virtualization_type != "docker" - name: Ensure NetworkManager does not fiddle DNS @@ -64,11 +68,13 @@ - name: Ensure correct permissions (hosts/resolv.conf) file: - path: "{{ item }}" + path: "{{ perm_config }}" state: touch mode: u+rw,g+r,a+r with_items: - /etc/resolv.conf - /etc/hosts + loop_control: + loop_var: perm_config changed_when: false tags: dns