SUMMARY
I'm trying to build a Dockerfile behind proxy using docker client config.json as described here.
Ansible docker_image default path for config.json is different that the one for docker client:
Docker docs: ~/.docker/config.json
Ansible docs: ~/docker/config.json
Trying to use DOCKER_CONFIG doesn't solve the problem:
$ echo DOCKER_CONFIG=/root/.docker >> /etc/environment
$ sudo su -
$ echo $DOCKER_CONFIG
/root/.docker
Links don't solve the problem:
# config.json for non privileged user in place
$ cat /home/tester/.docker/config.json
# config.json for root as we use become
# cat /root/.docker/config.json
{
"proxies":
{
"default":
{
"httpProxy": "http://myproxy.com:8080",
"httpsProxy": "http://myproxy.com:8080",
"noProxy": "127.0.0.1"
}
}
}
# adding a link
# ln -s .docker docker
# cat /root/docker/config.json
{
"proxies":
{
"default":
{
"httpProxy": "http://myproxy.com:8080",
"httpsProxy": "http://myproxy.com:8080",
"noProxy": "127.0.0.1"
}
}
}
ISSUE TYPE
- Bug Report
COMPONENT NAME
docker_image
ANSIBLE VERSION
ansible 2.7.7
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/tester/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]
CONFIGURATION
ansible-config dump --only-changed
OS / ENVIRONMENT
$ lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial
$ pip list |grep docker
docker (3.7.0)
$ docker version
Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.4
Git commit: e68fc7a
Built: Thu Jan 24 10:56:33 2019
OS/Arch: linux/amd64
Experimental: false
$ cat /etc/environment
http_proxy=http://myproxy.com:8080
ftp_proxy=http://myproxy.com:8080
https_proxy=http://myproxy.com:8080
no_proxy=127.0.0.1
$ env|grep -i proxy
http_proxy=http://myproxy.com:8080
ftp_proxy=http://myproxy.com:8080
https_proxy=http://myproxy.com:8080
no_proxy=127.0.0.1
STEPS TO REPRODUCE
$ cat Dockerfile
FROM ubuntu:16.04
RUN apt-get -y update
RUN apt install -y rsync
$ cat inventory
localhost
$ cat playbook.yml
---
- hosts: localhost
tasks:
- become: yes
docker_image:
path: .
name: aptupdate:latest
EXPECTED RESULTS
Ansible docker_image should successfully build a Dockerfile
ACTUAL RESULTS
Ansible docker_image skips docker client config.json
and the Dockerfile timeouts without proxies.
$ ansible-playbook -i inventory playbook.yml -v
PLAY [localhost] ***************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************
ok: [localhost]
TASK [docker_image] ************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error building aptupdate - code: 100, message: The command '/bin/sh -c apt install -y rsync' returned a non-zero code: 100, logs: [u'Step 1/3 : FROM ubuntu:16.04', u'\\n', u' ---> 9361ce633ff1\\n', u'Step 2/3 : RUN apt-get -y update', u'\\n', u' ---> Running in e11b537b34fd\\n', u'Err:1 http://archive.ubuntu.com/ubuntu xenial InRelease\\n Could not connect to archive.ubuntu.com:80 (91.189.88.161), connection timed out [IP: 91.189.88.161 80]\\nErr:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease\\n Unable to connect to archive.ubuntu.com:http: [IP: 91.189.88.161 80]\\nErr:3 http://archive.ubuntu.com/ubuntu xenial-backports InRelease\\n Unable to connect to archive.ubuntu.com:http: [IP: 91.189.88.161 80]\\n', u'Err:4 http://security.ubuntu.com/ubuntu xenial-security InRelease\\n Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out [IP: 91.189.88.152 80]\\n', u'Reading package lists...', u'\\n', u'\\x1b[91mW: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease Could not connect to archive.ubuntu.com:80 (91.189.88.161), connection timed out [IP: 91.189.88.161 80]\\nW: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease Unable to connect to archive.ubuntu.com:http: [IP: 91.189.88.161 80]\\nW: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-backports/InRelease Unable to connect to archive.ubuntu.com:http: [IP: 91.189.88.161 80]\\nW: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out [IP: 91.189.88.152 80]\\nW: Some index files failed to download. They have been ignored, or old ones used instead.\\n\\x1b[0m', u'Removing intermediate container e11b537b34fd\\n', u' ---> adc7a49df695\\n', u'Step 3/3 : RUN apt install -y rsync', u'\\n', u' ---> Running in a44021974022\\n', u'\\x1b[91m\\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.\\n\\n\\x1b[0m', u'Reading package lists...', u'\\n', u'Building dependency tree...', u'\\nReading state information...\\n', u'\\x1b[91mE: Unable to locate package rsync\\n\\x1b[0m', u'Removing intermediate container a44021974022\\n']"}
to retry, use: --limit @/home/tester/playbook.retry
PLAY RECAP *********************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1
NOTE: adding buildargs works as expected:
---
- hosts: localhost
tasks:
- become: yes
docker_image:
path: .
name: aptupdate:latest
buildargs:
http_proxy: "{{ proxy_env.http_proxy }}"
https_proxy: "{{ proxy_env.https_proxy }}"
no_proxy: "{{ proxy_env.no_proxy }}"