From ae358ce60e9700fb4ce84889b6140843d8669448 Mon Sep 17 00:00:00 2001 From: djpbessems Date: Fri, 22 Apr 2022 23:19:42 +0200 Subject: [PATCH] Replace w/ loop key; Change scope of polling task --- playbook.yml | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/playbook.yml b/playbook.yml index 7e7dd3c..fa1676d 100644 --- a/playbook.yml +++ b/playbook.yml @@ -37,11 +37,11 @@ guestinfo.prefixlength: "{{ item.ip | ansible.utils.ipaddr('prefix') }}" guestinfo.dnsserver: "{{ network.dnsserver }}" guestinfo.gateway: "{{ network.gateway }}" - delegate_to: localhost - with_items: "{{ servers }}" register: job_init async: 300 poll: 0 + delegate_to: localhost + loop: "{{ servers }}" - name: Pause to allow initial calls to complete ansible.builtin.pause: @@ -50,38 +50,38 @@ - name: Poll for completion ansible.builtin.async_status: jid: "{{ item.ansible_job_id }}" - with_items: "{{ job_init.results }}" register: job_poll retries: 5 delay: 100 until: job_poll.finished + loop: "{{ job_init.results }}" - name: Parse results into dictionary ansible.builtin.set_fact: nodes: "{{ nodes | default([]) + [ {'name': item.instance.hw_name, 'ip': item.item.item.ip | ansible.utils.ipaddr('address')} ] }}" - with_items: "{{ job_poll | json_query('results[*]') }}" - # Purely to avoid large amount of spam; no sensitive data here. - no_log: true + loop: "{{ job_poll | json_query('results[*]') }}" + loop_control: + label: "{{ { 'name': item.item.name, 'ip': item.item.ip } }}" - name: Register new VM's in inventory ansible.builtin.add_host: name: "{{ item.name }}" ansible_host: "{{ item.ip }}" groups: k3s_ha - with_items: "{{ nodes }}" + loop: "{{ nodes }}" - name: Wait for systems to become reachable over SSH ansible.builtin.wait_for: host: "{{ item.ip }}" port: 22 timeout: 300 - with_items: "{{ nodes }}" + loop: "{{ nodes }}" - name: Scan public keys ansible.builtin.shell: cmd: "ssh-keyscan -t rsa {{ item.ip }}" register: publickeys - with_items: "{{ nodes }}" + loop: "{{ nodes }}" - name: Store public keys ansible.builtin.known_hosts: @@ -89,9 +89,9 @@ key: "{{ item.item.name | lower }},{{ item.stdout }}" state: present path: ~/.ssh/known_hosts - with_items: "{{ publickeys.results }}" - # Purely to avoid large amount of spam; no sensitive data here. - no_log: true + loop: "{{ publickeys.results }}" + loop_control: + label: "{{ { 'name': item.item.name, 'ip': item.item.ip } }}" - name: Provision Kubernetes hosts: k3s_ha @@ -137,19 +137,19 @@ src: kube-vip.j2 dest: /var/lib/rancher/k3s/server/manifests/kube-vip.yml - - name: Initial node -- Wait for available API - ansible.utils.cli_parse: - command: "curl -k https://{{ cluster.virtualip | ansible.utils.ipaddr('address') }}:6443/livez?verbose" - parser: - name: ansible.utils.json - set_fact: api_readycheck - ignore_errors: yes - until: api_readycheck.apiVersion is defined - retries: 3 - delay: 30 + delegate_to: "{{ ansible_play_hosts[0] }}" + run_once: true - delegate_to: "{{ ansible_play_hosts[0] }}" - run_once: true + - name: All nodes -- Ensure API availability + ansible.utils.cli_parse: + command: "curl -k https://{{ cluster.virtualip | ansible.utils.ipaddr('address') }}:6443/livez?verbose" + parser: + name: ansible.utils.json + set_fact: api_readycheck + ignore_errors: yes + until: api_readycheck.apiVersion is defined + retries: 3 + delay: 30 - block: