69 lines
1.9 KiB
YAML
69 lines
1.9 KiB
YAML
---
|
|
- name: Add Beijing prefix to LXC node names in Nomad configuration
|
|
hosts: beijing
|
|
become: yes
|
|
|
|
vars:
|
|
node_prefixes:
|
|
influxdb: "bj-influxdb"
|
|
warden: "bj-warden"
|
|
hcp1: "bj-hcp1"
|
|
hcp2: "bj-hcp2"
|
|
tailscale_ips:
|
|
influxdb: "100.100.7.4"
|
|
warden: "100.122.197.112"
|
|
hcp1: "100.97.62.111"
|
|
hcp2: "100.116.112.45"
|
|
|
|
tasks:
|
|
- name: Stop Nomad service
|
|
systemd:
|
|
name: nomad
|
|
state: stopped
|
|
|
|
- name: Get current node name from inventory
|
|
set_fact:
|
|
current_node_name: "{{ inventory_hostname }}"
|
|
new_node_name: "{{ node_prefixes[inventory_hostname] }}"
|
|
tailscale_ip: "{{ tailscale_ips[inventory_hostname] }}"
|
|
|
|
- name: Display node name change
|
|
debug:
|
|
msg: "Changing node name from {{ current_node_name }} to {{ new_node_name }}, using Tailscale IP {{ tailscale_ip }}"
|
|
|
|
- name: Update node name in Nomad configuration
|
|
lineinfile:
|
|
path: /etc/nomad.d/nomad.hcl
|
|
regexp: '^name\s*='
|
|
line: 'name = "{{ new_node_name }}"'
|
|
insertafter: 'datacenter = "dc1"'
|
|
state: present
|
|
|
|
- name: Validate Nomad configuration
|
|
shell: nomad config validate /etc/nomad.d/nomad.hcl
|
|
register: config_validation
|
|
failed_when: config_validation.rc != 0
|
|
|
|
- name: Start Nomad service
|
|
systemd:
|
|
name: nomad
|
|
state: started
|
|
|
|
- name: Wait for Nomad to be ready on Tailscale IP
|
|
wait_for:
|
|
port: 4646
|
|
host: "{{ tailscale_ip }}"
|
|
delay: 10
|
|
timeout: 60
|
|
|
|
- name: Wait for node registration
|
|
pause:
|
|
seconds: 15
|
|
|
|
- name: Display new configuration
|
|
shell: cat /etc/nomad.d/nomad.hcl | grep -E "^(datacenter|name|bind_addr)\s*="
|
|
register: nomad_config_check
|
|
|
|
- name: Show updated configuration
|
|
debug:
|
|
var: nomad_config_check.stdout_lines |