<p>It appears that you are trying to run ansible locally <strong>inside</strong> the container but instead you are running it locally on the machine you use to run packer on(the provisioning one).</p>

<p>To run ansible in <a href="https://www.packer.io/docs/provisioners/ansible-local.html" rel="nofollow noreferrer">local mode</a> you need to update the ansible part of your packer file to:</p>

<pre><code>    {
        "type": "ansible-local",
        "playbook_file": "./kubeadm.yml"
    }
</code></pre>

<p>Also, I would suggest to add <code>connection: local</code> to your ansible playbook, to avoid unnecessary attempts for ssh connections.</p>

<pre><code>- name: install kubeadm
  hosts: localhost
  connection: local
  roles:
    - { role: djx339.k8s-kubeadm-install }
</code></pre>

CC BY-SA 3.0
2018-02-27T15:52:34.417Z
Tried it. Now I get `ERROR! the role 'djx339.k8s-kubeadm-install' was not found`
David West
CC BY-SA 3.0
2018-02-27T15:54:16.643Z
Can you post the contents of `setup_ansible.sh` as well?
man0v
CC BY-SA 3.0
2018-02-27T15:58:35.110Z
posted the contents of `setup_ansible.sh`
David West
CC BY-SA 3.0
2018-02-27T16:01:30.443Z
I see the error. in `add_ansible_roles.sh` I'm installing the wrong role.
David West
CC BY-SA 4.0
2018-11-24T10:35:46.357Z
Instead of `add_ansible_roles.sh` use https://packer.io/docs/provisioners/ansible-local.html#galaxy_file
Rickard von Essen
CC BY-SA 3.0
2018-02-25T18:15:17.130Z
2018-02-25T19:14:43.147Z
2018-02-25T19:14:43.147Z
man0v
<p>I have a Packer template to start with a Docker container and provision it.  The shell script provisioners seem to be working, but, while the playbook runs and seems to succeed, unlike the shell provisioners, it seems to not be applying to the Docker container.</p>

<p>packer-template.json</p>

<pre><code>{
  "builders": [
        {
            "type": "docker",
            "image": "chenjr0719/ubuntu-unity-novnc",
            "commit": "true"
        }
    ],
   "provisioners": [
        {
            "type": "shell",
            "inline": ["sudo apt-get update"]
        },
        {
            "type": "shell",
            "script": "setup_ansible.sh"
        },
        {
            "type": "shell",
            "script": "add_ansible_roles.sh"
        },
        {
            "type": "ansible",
            "playbook_file": "./kubeadm.yml"
        }
   ]
}
</code></pre>

<p>setup_ansible.sh</p>

<pre><code>sudo apt-get install software-properties-common -y
sudo apt-add-repository ppa:ansible/ansible -y
sudo apt-get update
sudo apt-get install ansible -y
</code></pre>

<p>add_ansible_roles.sh</p>

<pre><code>sudo ansible-galaxy install djx339.k8s-kubeadm-master
</code></pre>

<p>kubeadm.yml</p>

<pre><code>- name: install kubeadm
  hosts: localhost
  roles:
    - { role: djx339.k8s-kubeadm-install }
</code></pre>

<p>Output from the playbook</p>

<pre><code>docker: PLAY [install kubeadm] *********************************************************
docker:
docker: TASK [Gathering Facts] *********************************************************
docker: ok: [localhost]
docker:
docker: TASK [djx339.k8s-kubeadm-install : include_tasks] ******************************
docker: included: /home/dw/.ansible/roles/djx339.k8s-kubeadm-install/tasks/setup-Debian.yml for localhost
docker:
docker: TASK [djx339.k8s-kubeadm-install : Sysctl] *************************************
docker: ok: [localhost] =&gt; (item={u'name': u'net.bridge.bridge-nf-call-iptables', u'value': 1})
docker:
docker: TASK [djx339.k8s-kubeadm-install : Add kuebeadm apt key] ***********************
docker: ok: [localhost]
docker:
docker: TASK [djx339.k8s-kubeadm-install : Add kubeadm apt repo] ***********************
docker: ok: [localhost]
docker:
docker: TASK [djx339.k8s-kubeadm-install : Install kubeadm] ****************************
docker: ok: [localhost] =&gt; (item=[u'kubelet', u'kubeadm', u'kubectl', u'kubernetes-cni'])
docker:
docker: PLAY RECAP *********************************************************************
docker: localhost                  : ok=6    changed=0    unreachable=0    failed=0
</code></pre>

<p>Running <code>kubeadm</code> in the docker container throws an error.</p>

<p>Why isn't the playbook applying? It works when I run it locally.</p>

<p>The error which I'm getting is:</p>

<blockquote>
  <p>kubeadm not found</p>
</blockquote>

<p>So basically it's not installing <code>kubeadm</code>.</p>

<hr>

<p>Note: just noticed the mismatch between the role I'm adding in the <code>add_ansible_roles.sh</code> script and the playbook.</p>

CC BY-SA 3.0
2018-02-23T08:12:24.497Z
What error does it throw?
ydaetskcoR
CC BY-SA 3.0
2018-02-24T07:27:23.267Z
kubeadm not found. It is not installing kubeadm
David West
<docker><ansible><packer>
Ansible Remote provisioning not working in Docker container build
David West
# Ansible Remote provisioning not working in Docker container build

(Asked by: username_0 on 2018-02-22)

I have a Packer template to start with a Docker container and provision it.  The shell script provisioners seem to be working, but, while the playbook runs and seems to succeed, unlike the shell provisioners, it seems to not be applying to the Docker container.
packer-template.json
{
  "builders": [
        {
            "type": "docker",
            "image": "chenjr0719/ubuntu-unity-novnc",
            "commit": "true"
        }
    ],
   "provisioners": [
        {
            "type": "shell",
            "inline": ["sudo apt-get update"]
        },
        {
            "type": "shell",
            "script": "setup_ansible.sh"
        },
        {
            "type": "shell",
            "script": "add_ansible_roles.sh"
        },
        {
            "type": "ansible",
            "playbook_file": "./kubeadm.yml"
        }
   ]
}

setup_ansible.sh
sudo apt-get install software-properties-common -y
sudo apt-add-repository ppa:ansible/ansible -y
sudo apt-get update
sudo apt-get install ansible -y

add_ansible_roles.sh
sudo ansible-galaxy install djx339.k8s-kubeadm-master

kubeadm.yml
- name: install kubeadm
  hosts: localhost
  roles:
    - { role: djx339.k8s-kubeadm-install }

Output from the playbook
docker: PLAY [install kubeadm] *********************************************************
docker:
docker: TASK [Gathering Facts] *********************************************************
docker: ok: [localhost]
docker:
docker: TASK [djx339.k8s-kubeadm-install : include_tasks] ******************************
docker: included: /home/dw/.ansible/roles/djx339.k8s-kubeadm-install/tasks/setup-Debian.yml for localhost
docker:
docker: TASK [djx339.k8s-kubeadm-install : Sysctl] *************************************
docker: ok: [localhost] => (item={u'name': u'net.bridge.bridge-nf-call-iptables', u'value': 1})
docker:
docker: TASK [djx339.k8s-kubeadm-install : Add kuebeadm apt key] ***********************
docker: ok: [localhost]
docker:
docker: TASK [djx339.k8s-kubeadm-install : Add kubeadm apt repo] ***********************
docker: ok: [localhost]
docker:
docker: TASK [djx339.k8s-kubeadm-install : Install kubeadm] ****************************
docker: ok: [localhost] => (item=[u'kubelet', u'kubeadm', u'kubectl', u'kubernetes-cni'])
docker:
docker: PLAY RECAP *********************************************************************
docker: localhost                  : ok=6    changed=0    unreachable=0    failed=0

Running kubeadm in the docker container throws an error.
Why isn't the playbook applying? It works when I run it locally.
The error which I'm getting is:

kubeadm not found

So basically it's not installing kubeadm.

Note: just noticed the mismatch between the role I'm adding in the add_ansible_roles.sh script and the playbook.

**Tags:** docker, ansible, packer

> **Comments:**
> **username_1**: What error does it throw?  
> **username_0**: kubeadm not found. It is not installing kubeadm  

---

## 1 answers

### Answer by username_2 on 2018-02-25. Score: 3

It appears that you are trying to run ansible locally inside the container but instead you are running it locally on the machine you use to run packer on(the provisioning one).
To run ansible in local mode you need to update the ansible part of your packer file to:
    {
        "type": "ansible-local",
        "playbook_file": "./kubeadm.yml"
    }

Also, I would suggest to add connection: local to your ansible playbook, to avoid unnecessary attempts for ssh connections.
- name: install kubeadm
  hosts: localhost
  connection: local
  roles:
    - { role: djx339.k8s-kubeadm-install }

> **Comments:**
> **username_0**: Tried it. Now I get `ERROR! the role 'djx339.k8s-kubeadm-install' was not found`  
> **username_2**: Can you post the contents of `setup_ansible.sh` as well?  
> **username_0**: posted the contents of `setup_ansible.sh`  
> **username_0**: I see the error. in `add_ansible_roles.sh` I'm installing the wrong role.  
> **username_3**: Instead of `add_ansible_roles.sh` use https://packer.io/docs/provisioners/ansible-local.html#galaxy_file  

---

