Simplify logic using when clause
continuous-integration/drone/push Build encountered an error Details

This commit is contained in:
Danny Bessems 2022-04-20 12:31:42 +02:00
parent ab0c96c5e1
commit c8793cee43
1 changed files with 15 additions and 28 deletions

View File

@ -98,37 +98,24 @@
gather_facts: false
vars_files:
- cluster.k3s.yml
serial: 1
tasks:
- ansible.builtin.debug:
var: cluster
- name: Install K3s binary (initial node)
ansible.builtin.shell:
cmd: "curl -sfL https://get.k3s.io | sh -s - server --cluster-init --disable local-storage,traefik --tls-san {{ cluster.virtualip | ansible.utils.ipaddr('address') }}"
when: inventory_hostname == k3s_ha[0]
- name: Install K3s binary
- name: Retrieve token (from initial node)
ansible.builtin.slurp:
src: /var/lib/rancher/k3s/server/token
register: k3s_token
run_once: true
delegate_to: k3s_ha[0]
- name: Install K3s binary (additional nodes)
ansible.builtin.shell:
cmd: "curl -sfL https://get.k3s.io | sh -s - server --cluster-init --disable local-storage,traefik --tls-san {{ cluster.virtualip | ansible.utils.ipaddr('address') }}"
environment:
K3S_TOKEN: "{{ cluster.mastertoken | default('', true) }}"
K3S_URL: "{{ cluster.apiurl | default('', true) }}"
- name: Reference new cluster
block:
- name: Retrieve token
ansible.builtin.slurp:
src: /var/lib/rancher/k3s/server/token
register: k3s_token
- name: Update dictionary
ansible.builtin.set_fact:
cluster: >-
cluster | combine(
{ 'mastertoken': ( k3s_token.content | b64decode | trim ) },
{ 'apiurl': 'https://' + ( cluster.virtualip | ansible.utils.ipaddr('address') ) + ':6443' }
)
when: cluster.mastertoken is not defined
- ansible.builtin.debug:
var: cluster
K3S_TOKEN: "{{ k3s_token.content | b64decode | trim }}"
K3S_URL: "{{ 'https://' + ( cluster.virtualip | ansible.utils.ipaddr('address') ) + ':6443' }}"
when: inventory_hostname != k3s_ha[0]