--- - name: Create the kubernetes cluster using kubeadm hosts: masters become: true tasks: - name: Check for admin.conf from kubeadm stat: path=/etc/kubernetes/admin.conf register: admin_conf - set_fact: running: admin_conf.stat.exists - name: Create kubeadm join command shell: kubeadm token create --print-join-command register: results when: admin_conf.stat.exists == true - debug: var: results.stdout when: admin_conf.stat.exists == true - set_fact: token: "{{ results.stdout | regex_search(regexp, '\\2') | first }}" vars: regexp: '([^\s]+\s){4}([^\s]+)' when: admin_conf.stat.exists == true - debug: var: token when: admin_conf.stat.exists == true - set_fact: hash: "{{ results.stdout | regex_search(regexp, '\\1') | first }}" vars: regexp: '--discovery-token-ca-cert-hash ([^\s]+\s)' when: admin_conf.stat.exists == true - debug: var: hash when: admin_conf.stat.exists == true