32 lines
1.1 KiB
YAML
32 lines
1.1 KiB
YAML
- name: Set up Agents
|
|
hosts: k3s_nodes
|
|
gather_facts: yes
|
|
vars_files:
|
|
- secrets.yml
|
|
pre_tasks:
|
|
- name: Get K3s token from the first server
|
|
when: host.ip == k3s.server.ips[0] and inventory_hostname in groups["k3s_server"]
|
|
slurp:
|
|
src: /var/lib/rancher/k3s/server/node-token
|
|
register: k3s_token
|
|
become: true
|
|
|
|
- name: Set fact on k3s.server.ips[0]
|
|
when: host.ip == k3s.server.ips[0] and inventory_hostname in groups["k3s_server"]
|
|
set_fact: k3s_token="{{ k3s_token['content'] | b64decode | trim }}"
|
|
|
|
roles:
|
|
- role: common
|
|
when: inventory_hostname in groups["k3s_agent"]
|
|
tags:
|
|
- common
|
|
- role: k3s_agent
|
|
when: inventory_hostname in groups["k3s_agent"]
|
|
k3s_token: "{{ hostvars[(hostvars | dict2items | map(attribute='value') | map('dict2items') | map('selectattr', 'key', 'match', 'host') | map('selectattr', 'value.ip', 'match', k3s.server.ips[0] ) | select() | first | items2dict).host.hostname].k3s_token }}"
|
|
tags:
|
|
- k3s_agent
|
|
- role: node_exporter
|
|
when: inventory_hostname in groups["k3s_agent"]
|
|
tags:
|
|
- node_exporter
|