Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2020-01-25T21:58:28.227Z
Answers: Thanks. The second approach you suggested seems much cleaner. I'll go with that one.
Answers: Kyu96
Answers: CC BY-SA 4.0
Answers: 2020-01-25T18:22:11.973Z
Answers: 2020-01-26T20:48:52.357Z
Answers: 2020-01-26T20:48:52.357Z
Answers: Zeitounator
Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2020-01-24T20:58:44.963Z
Answers: Unfortunately, after installing gnupg, the exact same error persists. Can you reproduce the problem?
Answers: Kyu96
Answers: CC BY-SA 4.0
Answers: 2020-01-24T22:53:46.253Z
Answers: @Kyu96 You have to install `gnupg` before you use `apt-add-repository`
Answers: Zeitounator
Answers: CC BY-SA 4.0
Answers: 2020-01-25T17:23:27.210Z
Answers: @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..
Answers: Kyu96
Answers: CC BY-SA 4.0
Answers: 2020-01-24T20:49:15.977Z
Answers: 2020-01-25T08:40:56.617Z
Answers: 2020-01-25T08:40:56.617Z
Answers: Hedi Nasr
Body: <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>
  
Tags: <docker><ansible><packer><provisioning>
Title: Cannot install Ansible
UserDisplayName: Kyu96
ThreadText: # 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?
  [![enter image description here](https://i.sstatic.net/lKG1P.png)](https://i.sstatic.net/lKG1P.png)
  
  **EDIT**: After installing the gnupg package, there still seems to be issues that result in the building process to fail:
  
  [![](https://i.sstatic.net/knaf5.png)](https://i.sstatic.net/knaf5.png)
  
  **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](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-debian) 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..  
  
  ---
  
  