2019-03-09 21:54:44 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: Ensure ansible_host is mapped to inventory_hostname
|
|
|
|
lineinfile:
|
|
|
|
path: /tmp/inventory.txt
|
2019-10-01 22:31:35 +02:00
|
|
|
line: >-
|
|
|
|
{{ item }}
|
|
|
|
@@@
|
|
|
|
{{ hostvars[item].ansible_host | default(hostvars[item].ansible_fqdn) }}
|
|
|
|
@@@
|
2020-01-12 17:16:40 +01:00
|
|
|
C_{{ hostvars[item].k3s_control_node }}
|
|
|
|
@@@
|
|
|
|
P_{{ hostvars[item].k3s_primary_control_node | default(False) }}
|
2019-03-09 21:54:44 +01:00
|
|
|
create: true
|
|
|
|
loop: "{{ play_hosts }}"
|
|
|
|
|
|
|
|
- name: Lookup control node from file
|
2020-01-12 17:16:40 +01:00
|
|
|
command: "grep '{{ 'P_True' if (k3s_controller_count | length > 1) else 'C_True' }}' /tmp/inventory.txt"
|
2019-03-09 21:54:44 +01:00
|
|
|
changed_when: false
|
|
|
|
register: k3s_control_delegate_raw
|
|
|
|
|
|
|
|
- name: Ensure control node is delegated to for obtaining a token
|
|
|
|
set_fact:
|
2019-10-01 22:31:35 +02:00
|
|
|
k3s_control_delegate: "{{ k3s_control_delegate_raw.stdout.split(' @@@ ')[0] }}"
|
2019-03-09 21:54:44 +01:00
|
|
|
|
|
|
|
- name: Ensure the control node address is registered in Ansible
|
|
|
|
set_fact:
|
2019-10-01 22:31:35 +02:00
|
|
|
k3s_control_node_address: "{{ hostvars[k3s_control_delegate].ansible_host | default(hostvars[k3s_control_delegate].ansible_fqdn) }}"
|
2019-12-04 18:17:15 +01:00
|
|
|
when: k3s_control_node_address is not defined
|
2019-03-09 21:54:44 +01:00
|
|
|
|
|
|
|
- name: Ensure NODE_TOKEN is captured from control node
|
|
|
|
slurp:
|
|
|
|
path: "/var/lib/rancher/k3s/server/node-token"
|
2019-12-04 18:17:15 +01:00
|
|
|
register: k3s_slurped_control_token
|
2019-03-09 21:54:44 +01:00
|
|
|
delegate_to: "{{ k3s_control_delegate }}"
|
2019-12-04 18:17:15 +01:00
|
|
|
when: k3s_control_token is not defined
|
|
|
|
|
|
|
|
- name: Ensure NODE_TOKEN is formatted correctly for use in templates
|
|
|
|
set_fact:
|
|
|
|
k3s_control_token: "{{ k3s_slurped_control_token.content | b64decode }}"
|
|
|
|
when: k3s_control_token is not defined
|
2019-03-09 21:54:44 +01:00
|
|
|
|
|
|
|
- name: Ensure k3s service unit file is present
|
|
|
|
template:
|
|
|
|
src: k3s.service.j2
|
|
|
|
dest: /etc/systemd/system/k3s.service
|
|
|
|
notify:
|
2019-10-01 22:31:35 +02:00
|
|
|
- reload systemd
|
2019-03-09 21:54:44 +01:00
|
|
|
- restart k3s
|
|
|
|
|
2020-01-13 22:32:31 +01:00
|
|
|
- name: Ensure secondary masters are started
|
|
|
|
service:
|
|
|
|
name: k3s
|
|
|
|
state: started
|
|
|
|
enabled: true
|
2020-03-07 17:15:41 +01:00
|
|
|
register: ensure_secondary_masters_started
|
|
|
|
until: ensure_secondary_masters_started is succeeded
|
|
|
|
retries: "{{ play_hosts | length }}"
|
|
|
|
delay: 2
|
2020-01-13 22:32:31 +01:00
|
|
|
when: k3s_control_node and not k3s_primary_control_node
|
2019-03-09 21:54:44 +01:00
|
|
|
|
2019-10-01 22:31:35 +02:00
|
|
|
- name: Wait for control plane to be ready to accept connections
|
|
|
|
wait_for:
|
2019-10-26 23:49:48 +02:00
|
|
|
port: "{{ k3s_https_port }}"
|
2019-10-01 22:31:35 +02:00
|
|
|
delay: 5
|
|
|
|
sleep: 5
|
|
|
|
timeout: 300
|
|
|
|
when: k3s_control_node
|
|
|
|
|
2020-01-13 22:32:31 +01:00
|
|
|
- meta: flush_handlers
|
|
|
|
|
2019-03-09 21:54:44 +01:00
|
|
|
- name: Wait for all nodes to be ready
|
|
|
|
command: "{{ k3s_install_dir }}/kubectl get nodes"
|
|
|
|
changed_when: false
|
2019-10-01 22:31:35 +02:00
|
|
|
failed_when: false
|
2019-03-09 21:54:44 +01:00
|
|
|
register: kubectl_get_nodes_result
|
2019-10-01 22:31:35 +02:00
|
|
|
until: kubectl_get_nodes_result.rc == 0
|
|
|
|
and kubectl_get_nodes_result.stdout.find("NotReady") == -1
|
2019-03-09 21:54:44 +01:00
|
|
|
retries: 30
|
|
|
|
delay: 20
|
2020-03-07 15:23:09 +01:00
|
|
|
when: k3s_control_node and not k3s_no_flannel
|