<p>This is how I managed to test your scenario manually against the <code>php:7.0-apache</code> docker image. Note that this image is based on <code>debian:stretch</code>. In your question, you are following the install guide for ubuntu which will fail anyway in debian stretch.</p>

<p>I'm using the correct scenario below. See the <a href="https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-debian" rel="nofollow noreferrer">ansible install documentation</a> for more details. I also kept the install of sudo which was in your initial provisioning script.</p>

<pre><code>apt-get update
apt-get install -y gnupg sudo
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
echo deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main &gt;&gt; /etc/apt/sources.list
apt-get update
apt-get install -y ansible
apt-get clean
</code></pre>

<p>After playing this, result:</p>

<pre><code>root@18ab6da8ac92:/var/www/html# ansible --version              
ansible 2.9.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516]
</code></pre>

<p>Now, the above is installing ansible from deb packages that will run in python 2.7 that has been obsoleted. I much rather prefer the following scenario using pip that will install ansible as well but in python3 and does not need to add a supplementary apt repo neither requires to install gnupg</p>

<pre><code>apt-get update
apt-get install -y python3-pip
pip3 install --upgrade pip
pip install ansible
apt-get clean
</code></pre>

<p>And the result</p>

<pre><code>root@e6b73a5f1d59:/var/www/html# ansible --version
ansible 2.9.4
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.5/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516]
</code></pre>

CC BY-SA 4.0
2020-01-25T21:58:28.227Z
Thanks. The second approach you suggested seems much cleaner. I'll go with that one.
Kyu96
CC BY-SA 4.0
2020-01-25T18:22:11.973Z
2020-01-26T20:48:52.357Z
2020-01-26T20:48:52.357Z
Zeitounator
<p>As it says, <code>No such file or directory: 'gpg'</code>, so you probably need to install <code>gnupg</code> before adding the PPA repository:</p>

<pre><code>apt-get install gnupg
</code></pre>

CC BY-SA 4.0
2020-01-24T20:58:44.963Z
Unfortunately, after installing gnupg, the exact same error persists. Can you reproduce the problem?
Kyu96
CC BY-SA 4.0
2020-01-24T22:53:46.253Z
@Kyu96 You have to install `gnupg` before you use `apt-add-repository`
Zeitounator
CC BY-SA 4.0
2020-01-25T17:23:27.210Z
@Zeitounator @Hedi Nasr After installing the gnupg package correctly (before doing the `git-add-repository`) there still seem to be issues related to gpg? I am not sure what causes the build process to fail exactly..
Kyu96
CC BY-SA 4.0
2020-01-24T20:49:15.977Z
2020-01-25T08:40:56.617Z
2020-01-25T08:40:56.617Z
Hedi Nasr
<p>So I am creating a packer template for docker with the image <em>php:7.0-apache</em>.
I added a shell provisioner where I try to install ansible so I can provision the image:</p>

<pre><code>{
            "type": "shell",
            "inline": [
                "apt-get -y update",
                "apt-get install -y software-properties-common",
                "apt-add-repository ppa:ansible/ansible",
                "apt-get -y update",

                "apt-get install -y sudo",
                "apt-get install -y ansible"
            ]
        },
</code></pre>

<p>However, I get this error. Why is that?
<a href="https://i.sstatic.net/lKG1P.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lKG1P.png" alt="enter image description here"></a></p>

<p><strong>EDIT</strong>: After installing the gnupg package, there still seems to be issues that result in the building process to fail:</p>

<p><a href="https://i.sstatic.net/knaf5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/knaf5.png" alt=""></a></p>

<docker><ansible><packer><provisioning>
Cannot install Ansible
Kyu96
# Cannot install Ansible

(Asked by: username_0 on 2020-01-24)

So I am creating a packer template for docker with the image php:7.0-apache.
I added a shell provisioner where I try to install ansible so I can provision the image:
{
            "type": "shell",
            "inline": [
                "apt-get -y update",
                "apt-get install -y software-properties-common",
                "apt-add-repository ppa:ansible/ansible",
                "apt-get -y update",

                "apt-get install -y sudo",
                "apt-get install -y ansible"
            ]
        },

However, I get this error. Why is that?

EDIT: After installing the gnupg package, there still seems to be issues that result in the building process to fail:

**Tags:** docker, ansible, packer, provisioning


---

## 2 answers

### Answer by username_1 on 2020-01-25. Score: 1 | Accepted answer

This is how I managed to test your scenario manually against the php:7.0-apache docker image. Note that this image is based on debian:stretch. In your question, you are following the install guide for ubuntu which will fail anyway in debian stretch.
I'm using the correct scenario below. See the ansible install documentation for more details. I also kept the install of sudo which was in your initial provisioning script.
apt-get update
apt-get install -y gnupg sudo
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
echo deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main >> /etc/apt/sources.list
apt-get update
apt-get install -y ansible
apt-get clean

After playing this, result:
root@18ab6da8ac92:/var/www/html# ansible --version              
ansible 2.9.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516]

Now, the above is installing ansible from deb packages that will run in python 2.7 that has been obsoleted. I much rather prefer the following scenario using pip that will install ansible as well but in python3 and does not need to add a supplementary apt repo neither requires to install gnupg
apt-get update
apt-get install -y python3-pip
pip3 install --upgrade pip
pip install ansible
apt-get clean

And the result
root@e6b73a5f1d59:/var/www/html# ansible --version
ansible 2.9.4
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.5/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516]

> **Comments:**
> **username_0**: Thanks. The second approach you suggested seems much cleaner. I'll go with that one.  

---

### Answer by username_2 on 2020-01-24. Score: 3

As it says, No such file or directory: 'gpg', so you probably need to install gnupg before adding the PPA repository:
apt-get install gnupg

> **Comments:**
> **username_0**: Unfortunately, after installing gnupg, the exact same error persists. Can you reproduce the problem?  
> **username_1**: @username_0 You have to install `gnupg` before you use `apt-add-repository`  
> **username_0**: @username_1 @username_2 After installing the gnupg package correctly (before doing the `git-add-repository`) there still seem to be issues related to gpg? I am not sure what causes the build process to fail exactly..  

---

