35 lines
934 B
YAML
35 lines
934 B
YAML
---
|
|
- name: Retrieve current hostsfile contents
|
|
ansible.builtin.command:
|
|
cmd: cat /etc/hosts
|
|
changed_when: false
|
|
register: _existing_hostsfile_raw
|
|
|
|
- name: Assemble hostsfile lines
|
|
vars:
|
|
_hostsfile_lines: []
|
|
ansible.builtin.set_fact:
|
|
_hostsfile_lines: "{{ _hostsfile_lines + [item.address + ' ' + item.hostname] }}"
|
|
loop: "{{ skylab_direct_peers }}"
|
|
loop_control:
|
|
label: "{{ item.hostname }}"
|
|
|
|
- name: Configure directly connected peers
|
|
become: true
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/hosts
|
|
line: "{{ item }}"
|
|
state: present
|
|
loop: "{{ _hostsfile_lines }}"
|
|
loop_control:
|
|
label: "{{ item.partition(' ')[0] }}"
|
|
|
|
- name: Remove unmanaged peer aliases
|
|
become: true
|
|
when: "'localhost' not in item and item not in _hostsfile_lines"
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/hosts
|
|
line: "{{ item }}"
|
|
state: absent
|
|
loop: "{{ _existing_hostsfile_raw.stdout_lines }}"
|