<p>I'm running a Kubernetes cluster on bare metal and I'm writing an Ansible task to get the join command from a master node:</p>

<pre><code>- name: Get join command from master
  shell: kubeadm token create --print-join-command
  when: role == "master"
  run_once: true
  register: join_command
</code></pre>

<p>When I run the playbook, I got the following error: "unable to create bootstrap token after 5 attempts []".</p>

<p>If I run the exact same command (<code>kubeadm token create --print-join-command</code>) directly on the master host or remotely using <code>ssh kube-master kubeadm token create --print-join-command</code>, it outputs the join command correctly.</p>

<p>I've ran out of options here... any ideas?</p>

<p>You can get that error if your "kubeadm" cannot connect to the Kubernetes cluster using credentials from the configuration file. You can reproduce it by stopping the <code>docker</code> service on your master node.</p>

<p>There is no difference between running the command using Ansible or shell in your case, so it should work.</p>

<p>So, the only things I can suggest are:</p>

<ol>
<li>Verify that the Ansible role <code>master</code> is attached to the right host.</li>
<li>Check if the Ansible user has access to the <code>kubeadm</code> configuration, its default path is <code>/etc/kubernetes/admin.conf</code>, and make sure that configuration is right. You might try to run the command as root using the <code>become: true</code> option.</li>
</ol>
