<p>I have an Ansible script that installs a Kubernetes cluster and is supposed to enable the dashboard. One task is giving me issues: </p>

<pre><code>- name: Expose Dashboard UI
  shell: kubectl proxy --port=8001 --address={{ hostvars['master'].master_node_ip }} --accept-hosts="^*$" &gt;&gt; dashboard_started.txt
  args:
    chdir: $HOME
    creates: dashboard_started.txt
</code></pre>

<p>The problem is that this works, but the command <code>kubectl proxy</code> is blocking: you can't type in another command until you ctrl+c out of the command, at which point the dashboard is inaccessible. My Ansible script freezes from performing this command. I can successfully connect to the dashboard in my browser while Ansible is frozen. But I need Ansible to perform other tasks after this one as well. I have tried adding an ampersand <code>&amp;</code> at the end of my command: </p>

<p><code>kubectl proxy --port=8001 --address={{ hostvars['master'].master_node_ip }} --accept-hosts="^*$" &gt;&gt; dashboard_started.txt &amp;</code></p>

<p>Or</p>

<p><code>kubectl proxy --port=8001 --address={{ hostvars['master'].master_node_ip }} --accept-hosts="^*$" &amp; &gt;&gt; dashboard_started.txt</code></p>

<p>And while both these commands cause Ansible to execute and pass over my task, I can't reach the dashboard. Using the <code>jobs</code> command on the machine the command is run on shows no background tasks, either for root or the Ansible user. </p>

<p>What am I doing wrong? </p>

<p>EDIT: </p>

<p>To those reading this: <strong>DO NOT DO THIS UNLESS YOU CAN ACCESS THE DASHBOARD FROM LOCALHOST</strong>. If you are running Kubernetes Dashboard in a VM or on some external server, and are trying to access it from another machine (the VM host for example), you will NOT be able to log in. See here: </p>

<p><a href="https://github.com/kubernetes/dashboard/blob/master/docs/user/accessing-dashboard/1.7.x-and-above.md" rel="nofollow noreferrer">https://github.com/kubernetes/dashboard/blob/master/docs/user/accessing-dashboard/1.7.x-and-above.md</a></p>

<blockquote>
  <p>NOTE: Dashboard should not be exposed publicly using kubectl proxy
  command as it only allows HTTP connection. For domains other than
  localhost and 127.0.0.1 it will not be possible to sign in. Nothing
  will happen after clicking Sign in button on login page.</p>
</blockquote>

yesman
<p>You could run the task with the asynchronous option. For example:</p>

<pre><code>- name: Expose Dashboard UI
  shell: "(kubectl proxy --port=8001 --address={{ hostvars['master'].master_node_ip }} --accept-hosts="^*$" &gt;&gt; dashboard_started.txt &gt;/dev/null 2&gt;&amp;1 &amp;)"
  args:
    chdir: $HOME
    creates: dashboard_started.txt
  async: 10
  poll: 0
</code></pre>

<p>When poll is 0, Ansible will start the task and immediately move on to the next one without waiting for a result.</p>

<p>I personally added the subshell parentheses though i suppose that there is no need to use them, async itself does the trick I hope!</p>

<p>Hope it helps!</p>

<p><a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html" rel="nofollow noreferrer">https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html</a></p>
