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

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


2 Answers 2


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]
  • Thanks. The second approach you suggested seems much cleaner. I'll go with that one.
    – Kyu96
    Jan 25, 2020 at 21:58

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
  • Unfortunately, after installing gnupg, the exact same error persists. Can you reproduce the problem?
    – Kyu96
    Jan 24, 2020 at 20:58
  • 1
    @Kyu96 You have to install gnupg before you use apt-add-repository Jan 24, 2020 at 22:53
  • @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
    Jan 25, 2020 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.