- name: Install the primary node block: - name: Set the primary IP fact set_fact: primary_ip: "{{ ansible_default_ipv4.address }}" - copy: content={{ primary_ip }} dest="{{ playbook_dir }}/config/primary_ip" become: false delegate_to: localhost - name: Run the installer shell: cmd: "curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC='server --cluster-init --tls-san {{ cp_fqdn }} --write-kubeconfig-mode 644' sh -" args: creates: /etc/rancher/k3s/k3s.yaml register: installed_primary - name: Download kubeconfig file fetch: src: /etc/rancher/k3s/k3s.yaml dest: "{{ playbook_dir }}/config/" flat: yes - name: Download the node join token fetch: src: /var/lib/rancher/k3s/server/token dest: "{{ playbook_dir }}/config/" flat: yes - name: Fix URL for control plane shell: cmd: sed -i.bak "s/127.0.0.1/{{ ansible_default_ipv4.address }}/g" {{playbook_dir}}/config/k3s.yaml become: false delegate_to: localhost - name: Pause to let the service come up wait_for: timeout: 60 become: false delegate_to: localhost when: installed_primary.changed become: true when: "'primary' in group_names"