Added loop_controls
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-11-02 12:07:24 +13:00
parent fa6e6b9a75
commit 0de26dd85e

View File

@@ -1,9 +1,9 @@
--- ---
- name: Ensure DNS and SSH common config - name: Ensure DNS and SSH common config
template: template:
src: "{{ item.src }}" src: "{{ network_config.src }}"
dest: "{{ item.dest }}" dest: "{{ network_config.dest }}"
mode: "{{ item.mode }}" mode: "{{ network_config.mode }}"
backup: yes backup: yes
with_items: with_items:
- { - {
@@ -14,13 +14,15 @@
} }
- { src: etc.resolv.conf.j2, dest: /etc/resolv.conf, mode: u+rw, a+r } - { src: etc.resolv.conf.j2, dest: /etc/resolv.conf, mode: u+rw, a+r }
when: ansible_virtualization_type != "docker" when: ansible_virtualization_type != "docker"
loop_control:
loop_var: network_config
tags: dns tags: dns
- name: Ensure hosts file correct - name: Ensure hosts file correct
lineinfile: lineinfile:
dest: /etc/hosts dest: /etc/hosts
regexp: "{{ item.regexp }}" regexp: "{{ hosts_config.regexp }}"
line: "{{ item.line }}" line: "{{ hosts_config.line }}"
backrefs: yes backrefs: yes
backup: yes backup: yes
with_items: with_items:
@@ -48,6 +50,8 @@
regexp: "^{{ ansible_default_ipv4.address }}.*{{ ansible_nodename.split('.')[0] }}$", regexp: "^{{ ansible_default_ipv4.address }}.*{{ ansible_nodename.split('.')[0] }}$",
line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }}.{{ domain }} {{ inventory_hostname }}", line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }}.{{ domain }} {{ inventory_hostname }}",
} }
loop_control:
loop_var: hosts_config
when: ansible_virtualization_type != "docker" when: ansible_virtualization_type != "docker"
- name: Ensure NetworkManager does not fiddle DNS - name: Ensure NetworkManager does not fiddle DNS
@@ -64,11 +68,13 @@
- name: Ensure correct permissions (hosts/resolv.conf) - name: Ensure correct permissions (hosts/resolv.conf)
file: file:
path: "{{ item }}" path: "{{ perm_config }}"
state: touch state: touch
mode: u+rw,g+r,a+r mode: u+rw,g+r,a+r
with_items: with_items:
- /etc/resolv.conf - /etc/resolv.conf
- /etc/hosts - /etc/hosts
loop_control:
loop_var: perm_config
changed_when: false changed_when: false
tags: dns tags: dns