ansible / ansible-container

DEPRECATED -- Ansible Container was a tool to build Docker images and orchestrate containers using only Ansible playbooks.
GNU Lesser General Public License v3.0
2.19k stars 392 forks source link

/bin/sh: 1: /_usr/bin/python: not found #904

Open drzraf opened 6 years ago

drzraf commented 6 years ago
ISSUE TYPE
container.yml
version: "2"
settings:
  conductor:
    base: alpine:latest
  wpdb:
    from: mariadb:latest
    roles:
      - { role: mysql, mysql: "{% raw %} {{ site.mysql }} {% endraw %}" }
    ports: 
      - "3306:3306"
OS / ENVIRONMENT
Ansible Container, version 0.9.2
Linux, 4.9.0-5-amd64, #1 SMP Debian 4.9.65-3+deb9u2 (2018-01-04), x86_64
2.7.13 (default, Nov 24 2017, 17:33:09)
SUMMARY

I can't provision mariadb (based on Debian Jessie) using Alpine as a connector.

STEPS TO REPRODUCE

mysql/tasks/main.yml

- name: Create mysql database
  mysql_db: name="{{ mysql.db }}" state=present
EXPECTED RESULTS

image built

ACTUAL RESULTS
ansible-playbook 2.5.0
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.13 (default, Dec 22 2016, 09:22:15) [GCC 6.2.1 20160822]
[...]
<f1638292cd4472b0f0f719e024687d5ce1a9143674e4965b4f17568d27492f3f> EXEC ['/usr/local/bin/docker', 'exec', '-i', u'f1638292cd4472b0f0f719e024687d5ce1a9143674e4965b4f17568d27492f3f', u'/bin/sh', '-c', u'/bin/sh -c \'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1520948786.2-72874583801818/setup.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1520948786.2-72874583801818/" > /dev/null 2>&1 && sleep 0\'']
fatal: [wpdb]: FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "/bin/sh: 1: /_usr/bin/python: not found\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 0
}

NOTE 1:

Running this raw task with gather_facts: no: - raw: "ls -l /_usr/bin/python*" shows that the executable actually exists:

<30d2d9db2593af00f6ebdc413a47890e6ce1b061b13bb88c1dfad1f4385417ee> EXEC ['/usr/local/bin/docker', 'exec', '-i', u'30d2d9db2593af00f6ebdc413a47890e6ce1b061b13bb88c1dfad1f4385417ee', u'/bin/sh', '-c', u'ls -l /_usr/bin/python*']
changed: [wpdb] => {
    "changed": true,
    "failed": false,
    "rc": 0,
    "stderr": "",
[...]
    "stdout_lines": [
        "lrwxrwxrwx 1 root root    7 Sep 16 10:56 /_usr/bin/python -> python2",
        "lrwxrwxrwx 1 root root   14 Sep 16 10:56 /_usr/bin/python-config -> python2-config",
        "lrwxrwxrwx 1 root root    9 Sep 16 10:56 /_usr/bin/python2 -> python2.7",
        "lrwxrwxrwx 1 root root   16 Sep 16 10:56 /_usr/bin/python2-config -> python2.7-config",
        "-rwxr-xr-x 1 root root 5808 Dec 22  2016 /_usr/bin/python2.7",
        "-rwxr-xr-x 1 root root 1681 Dec 22  2016 /_usr/bin/python2.7-config"
    ]
}

NOTE 2:

30d2d9db2593 being the container:

docker exec -ti  30d2d9db2593 /_usr/bin/python2.7 --help
OCI runtime exec failed: exec failed: container_linux.go:296: starting container process caused "no such file or directory": unknown

and the file actually exists in /_usr/bin, is an executable:

$ ls -l /_usr/bin/python2.7
-rwxr-xr-x 1 root root 5808 Dec 22  2016 /_usr/bin/python2.7
$ md5sum /_usr/bin/python2.7
ea4bf93fec727e9626f70554b7ff7005  /_usr/bin/python2.7
$ dd if=/usr/bin/python2.7 of=/dev/stdout bs=1 count=5 status=none
ELF

The same applies for all binaries not symlinked to /bin/busybox, ex:

/_usr/bin/ssh -V
bash: /_usr/bin/ssh: No such file or directory

WORKAROUND:

Install Python3 in the guest mariadb container, using: In container.yml - { role: mysql, gather_facts: no, ansible_python_interpreter: "/usr/bin/python3", mysql: "{% raw %} {{ site.mysql }} {% endraw %}" }

In mysql/tasks/main.yml - raw: "apt-get update && apt-get -y install python3-minimal"

Run with: ansible-container --debug --vars-files vars/main.yml build --use-local-python

See also : #511

Voronenko commented 6 years ago

@drzraf Unfortunately , I believe this is expected behavior: conductor needs to be compatible OS system. This introduces side effects of course, when your services are based on different base images. Ideally, there should be possibility to override conductor on per service basis.