Add hostfile management to server role
Add aliases for direct connections of the cluster servers
This commit is contained in:
parent
197157b830
commit
8ac7e0f5a3
@ -34,6 +34,13 @@ en1:
|
|||||||
- server
|
- server
|
||||||
- docker-swarm
|
- docker-swarm
|
||||||
- datastore
|
- datastore
|
||||||
|
skylab_direct_peers:
|
||||||
|
- hostname: pegasus.local
|
||||||
|
address: 192.168.42.10
|
||||||
|
- hostname: saturn.local
|
||||||
|
address: 192.168.42.20
|
||||||
|
- hostname: orion.local
|
||||||
|
address: 192.168.42.30
|
||||||
|
|
||||||
hosts:
|
hosts:
|
||||||
pegasus: # jupiter
|
pegasus: # jupiter
|
||||||
|
34
roles/server/tasks/hosts.yaml
Normal file
34
roles/server/tasks/hosts.yaml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
- 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 }}"
|
@ -8,3 +8,7 @@
|
|||||||
- name: Configure network settings
|
- name: Configure network settings
|
||||||
when: skylab_networking is defined
|
when: skylab_networking is defined
|
||||||
ansible.builtin.include_tasks: networkd.yaml
|
ansible.builtin.include_tasks: networkd.yaml
|
||||||
|
|
||||||
|
- name: Configure hostsfile
|
||||||
|
when: skylab_direct_peers is defined
|
||||||
|
ansible.builtin.include_tasks: hosts.yaml
|
||||||
|
Reference in New Issue
Block a user