Simplify logic using when clause
	
		
			
	
		
	
	
		
	
		
			Some checks reported errors
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build encountered an error
				
			
		
		
	
	
				
					
				
			
		
			Some checks reported errors
		
		
	
	continuous-integration/drone/push Build encountered an error
				
			This commit is contained in:
		
							
								
								
									
										37
									
								
								playbook.yml
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								playbook.yml
									
									
									
									
									
								
							@@ -98,37 +98,24 @@
 | 
				
			|||||||
  gather_facts: false
 | 
					  gather_facts: false
 | 
				
			||||||
  vars_files:
 | 
					  vars_files:
 | 
				
			||||||
  - cluster.k3s.yml
 | 
					  - cluster.k3s.yml
 | 
				
			||||||
  serial: 1
 | 
					 | 
				
			||||||
  tasks:
 | 
					  tasks:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  - ansible.builtin.debug:
 | 
					  - name: Install K3s binary (initial node)
 | 
				
			||||||
      var: cluster
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  - name: Install K3s binary
 | 
					 | 
				
			||||||
    ansible.builtin.shell:
 | 
					    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') }}"
 | 
					      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:
 | 
					    when: inventory_hostname == k3s_ha[0]
 | 
				
			||||||
      K3S_TOKEN: "{{ cluster.mastertoken | default('', true) }}"
 | 
					 | 
				
			||||||
      K3S_URL: "{{ cluster.apiurl | default('', true) }}"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  - name: Reference new cluster
 | 
					  - name: Retrieve token (from initial node)
 | 
				
			||||||
    block:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    - name: Retrieve token
 | 
					 | 
				
			||||||
    ansible.builtin.slurp:
 | 
					    ansible.builtin.slurp:
 | 
				
			||||||
      src: /var/lib/rancher/k3s/server/token
 | 
					      src: /var/lib/rancher/k3s/server/token
 | 
				
			||||||
    register: k3s_token
 | 
					    register: k3s_token
 | 
				
			||||||
 | 
					    run_once: true
 | 
				
			||||||
 | 
					    delegate_to: k3s_ha[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    - name: Update dictionary
 | 
					  - name: Install K3s binary (additional nodes)
 | 
				
			||||||
      ansible.builtin.set_fact:
 | 
					    ansible.builtin.shell:
 | 
				
			||||||
        cluster: >-
 | 
					      cmd: "curl -sfL https://get.k3s.io | sh -s - server --cluster-init --disable local-storage,traefik --tls-san {{ cluster.virtualip | ansible.utils.ipaddr('address') }}"
 | 
				
			||||||
          cluster | combine(
 | 
					    environment:
 | 
				
			||||||
             { 'mastertoken': ( k3s_token.content | b64decode | trim ) },
 | 
					      K3S_TOKEN: "{{ k3s_token.content | b64decode | trim }}"
 | 
				
			||||||
             { 'apiurl': 'https://' + ( cluster.virtualip | ansible.utils.ipaddr('address') ) + ':6443' }
 | 
					      K3S_URL: "{{ 'https://' + ( cluster.virtualip | ansible.utils.ipaddr('address') ) + ':6443' }}"
 | 
				
			||||||
          )
 | 
					    when: inventory_hostname != k3s_ha[0]
 | 
				
			||||||
 | 
					 | 
				
			||||||
    when: cluster.mastertoken is not defined
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  - ansible.builtin.debug:
 | 
					 | 
				
			||||||
      var: cluster
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user