Can't build simple-playbook from scratch: Failed to create temporary directory
soliverr opened this issue · 4 comments
Hi,
I've started to play with ansible-bender and I got an error:
$ ansible-bender -vvv build ./simple-playbook.yaml
18:05:23.264 utils.py INFO running command: "['ansible-playbook', '--version']"
18:05:23.569 utils.py INFO running command: "['ansible-playbook', '-c', 'local', '-i', '/tmp/ab0dh1a6_z/i', '-e', 'ansible_python_interpreter=/usr/bin/python3', './.simple-playbook-20220613180523263829-jjgqzushuv.yaml']"
18:05:24.434 utils.py INFO running command: "['podman', 'version']"
18:05:24.591 utils.py INFO running command: "['buildah', 'version']"
18:05:24.634 utils.py INFO running command: "['buildah', 'from', '--name', 'a-very-nice-image-20220613-180524432104-cont-20220613180524634644', 'python:3-alpine']"
18:05:27.446 utils.py INFO running command: "['buildah', 'run', 'a-very-nice-image-20220613-180524432104-cont-20220613180524634644', 'true']"
18:05:27.785 utils.py INFO running command: "['buildah', 'rm', 'a-very-nice-image-20220613-180524432104-cont-20220613180524634644']"
18:05:27.874 utils.py INFO running command: "['buildah', 'inspect', '-t', 'image', 'python:3-alpine']"
18:05:27.946 utils.py INFO running command: "['podman', 'run', '--rm', 'python:3-alpine', 'true']"
18:05:28.296 utils.py INFO running command: "['buildah', 'inspect', '-t', 'image', 'python:3-alpine']"
18:05:28.373 utils.py INFO running command: "['podman', 'run', '--rm', 'python:3-alpine', 'ls', '/usr/bin/python3']"
18:05:28.727 buildah_builder.py INFO python interpreter /usr/bin/python3 does not exist
18:05:28.727 utils.py INFO running command: "['podman', 'run', '--rm', 'python:3-alpine', 'ls', '/usr/local/bin/python3']"
18:05:29.261 buildah_builder.py INFO using python interpreter /usr/local/bin/python3
18:05:29.261 utils.py INFO running command: "['buildah', 'from', '-v', '/home/oliver-staff/tmp:/src', '--name', 'a-very-nice-image-20220613-180524432104-cont', '27edb73bd1fceae9fa3f3456b0979b7bdb9ad0ce9c0786c867598b3d7f702379']"
18:05:29.513 utils.py INFO running command: "['buildah', 'config', '--workingdir', '/src', '-e', 'FILE_TO_PROCESS=README.md', '-l', 'built-by=test', 'a-very-nice-image-20220613-180524432104-cont']"
18:05:29.736 core.py INFO creating inventory file /tmp/abwn4xogeq/inventory
18:05:29.752 utils.py INFO running command: "['ansible-playbook', '--version']"
18:05:30.146 core.py INFO we are running rootless, prepending `buildah unshare`
18:05:30.146 utils.py INFO running command: "['buildah', 'unshare', '--', 'ansible-playbook', '-c', 'buildah', '-i', '/tmp/abwn4xogeq/inventory', './.simple-playbook-20220613-180529751423-gutbmibgnz.yaml']"
PLAY [Demonstration of ansible-bender functionality] ***************************
TASK [Gathering Facts] *********************************************************
fatal: [a-very-nice-image-20220613-180524432104-cont]: UNREACHABLE! => {"changed": false, "msg": "Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p \"` echo /tmp `\"&& mkdir \"` echo /tmp/ansible-tmp-1655125530.7092428-197706-225038948075708 `\" && echo ansible-tmp-1655125530.7092428-197706-225038948075708=\"` echo /tmp/ansible-tmp-1655125530.7092428-197706-225038948075708 `\" ), exited with result 125", "unreachable": true}
PLAY RECAP *********************************************************************
a-very-nice-image-20220613-180524432104-cont : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
My stack:
$ lsb_release --all
LSB Version: core-11.1.0ubuntu4-noarch:printing-11.1.0ubuntu4-noarch:security-11.1.0ubuntu4-noarch
Distributor ID: Ubuntu
Description: Ubuntu 22.04 LTS
Release: 22.04
Codename: jammy
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.10.4 (main, Apr 2 2022, 09:04:19) [GCC 11.2.0]
$ ansible-bender --version
0.9.0
What should I tune in ansible or in ansible-bender to make it working?
Thank you.
This is surprising. Are you able to create a directory in /tmp with your unprivileged user?
Yes, I've checked this at first:
oliver@soliver:~$ whoami
oliver
oliver@soliver:~$ mkdir /tmp/test
oliver@soliver:~$ ls -ld /tmp/test
drwxrwxr-x 1 oliver oliver 0 июн 14 11:03 /tmp/test
May be problem is in container? Is there any option to keep working files alive when ansible-bender fails? It seems, I need to reproduce failed build step by hand.
You're right, 'gathering facts' phase is about accessing the container. You can also rerun with --debug
that provides detailed info what's happening in the background. This is how it looks on my laptop:
09:52:24.825 utils.py DEBUG TASK [Gathering Facts] *********************************************************
09:52:24.825 utils.py DEBUG task path: /home/tt/g/ansible-community/ansible-bender/.simple-playbook-20220614-095223694339-lxqpulujwv.yaml:1
09:52:24.832 utils.py DEBUG redirecting (type: connection) ansible.builtin.buildah to containers.podman.buildah
09:52:24.839 utils.py DEBUG <a-very-nice-image-20220614-095215414275-cont> RUN [b'buildah', b'mount', b'a-very-nice-image-20220614-095215414275-cont']
09:52:24.871 utils.py DEBUG <a-very-nice-image-20220614-095215414275-cont> RUN [b'buildah', b'run', b'a-very-nice-image-20220614-095215414275-cont', b'/bin/sh', b'-c', b'( umask 77 && mkdir -p "` echo /tmp `"&& mkdir "` echo /
tmp/ansible-tmp-1655193144.8394923-2080824-203575062820319 `" && echo ansible-tmp-1655193144.8394923-2080824-203575062820319="` echo /tmp/ansible-tmp-1655193144.8394923-2080824-203575062820319 `" ) && sleep 0']
09:52:25.301 utils.py DEBUG Using module file /usr/lib/python3.10/site-packages/ansible/modules/setup.py
09:52:25.301 utils.py DEBUG <a-very-nice-image-20220614-095215414275-cont> PUT /home/tt/.ansible/tmp/ansible-local-2080790s42tm1km/tmpubqtqgpr TO /tmp/ansible-tmp-1655193144.8394923-2080824-203575062820319/AnsiballZ_setup.py
09:52:25.302 utils.py DEBUG <a-very-nice-image-20220614-095215414275-cont> RUN [b'buildah', b'run', b'a-very-nice-image-20220614-095215414275-cont', b'/bin/sh', b'-c', b'chmod u+x /tmp/ansible-tmp-1655193144.8394923-2080824-20
3575062820319/ /tmp/ansible-tmp-1655193144.8394923-2080824-203575062820319/AnsiballZ_setup.py && sleep 0']
09:52:25.510 utils.py DEBUG <a-very-nice-image-20220614-095215414275-cont> RUN [b'buildah', b'run', b'a-very-nice-image-20220614-095215414275-cont', b'/bin/sh', b'-c', b'/usr/local/bin/python3 /tmp/ansible-tmp-1655193144.83949
23-2080824-203575062820319/AnsiballZ_setup.py && sleep 0']
09:52:26.500 utils.py DEBUG <a-very-nice-image-20220614-095215414275-cont> RUN [b'buildah', b'run', b'a-very-nice-image-20220614-095215414275-cont', b'/bin/sh', b'-c', b'rm -f -r /tmp/ansible-tmp-1655193144.8394923-2080824-203
575062820319/ > /dev/null 2>&1 && sleep 0']
09:52:26.710 utils.py DEBUG <a-very-nice-image-20220614-095215414275-cont> RUN [b'buildah', b'umount', b'a-very-nice-image-20220614-095215414275-cont']
09:52:26.736 utils.py DEBUG ok: [a-very-nice-image-20220614-095215414275-cont]
09:52:26.745 utils.py DEBUG META: ran handlers
09:52:26.753 utils.py DEBUG
Does these buildah
commands work for you okay?
$ buildah from docker.io/library/python:3-alpine
python-working-container
$ buildah run python-working-container mkdir /tmp/asdqwe
$ buildah run python-working-container ls -lha /tmp/asdqwe
total 0
drwxr-xr-x 1 root root 0 Jun 14 07:55 .
drwxrwxrwt 1 root root 12 Jun 14 07:55 ..
buildah
works okay:
$ buildah images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/python 3-alpine 27edb73bd1fc 7 days ago 50.6 MB
$ buildah run python-working-container mkdir /tmp/asdqwe
$ buildah run python-working-container ls -lha /tmp/asdqwe
total 0
drwxr-xr-x 1 root root 0 Jun 15 07:15 .
drwxrwxrwt 1 root root 12 Jun 15 07:15 ..
$ buildah run python-working-container ls -lha /tmp
total 260K
drwxrwxrwt 1 root root 12 Jun 15 07:15 .
dr-xr-xr-x 1 root root 18 Jun 15 07:15 ..
drwxr-xr-x 1 root root 0 Jun 15 07:15 asdqwe
-rw------- 1 root root 259.7K Jun 7 19:26 tmpjej62b9rcacert.pem
Here is my trace:
12:18:17.493 utils.py DEBUG TASK [Gathering Facts] *********************************************************
12:18:17.493 utils.py DEBUG task path: /home/oliver-staff/tmp/.simple-playbook-20220615-121816758369-etwwwhqcfo.yaml:1
12:18:17.499 utils.py DEBUG redirecting (type: connection) ansible.builtin.buildah to containers.podman.buildah
12:18:17.504 utils.py DEBUG <a-very-nice-image-20220615-121811914735-cont> RUN [b'buildah', b'mount', b'a-very-nice-image-20220615-121811914735-cont']
12:18:17.529 utils.py DEBUG <a-very-nice-image-20220615-121811914735-cont> RUN [b'buildah', b'run', b'--user', b'test', b'a-very-nice-image-20220615-121811914735-cont', b'/bin/sh', b'-c', b'( umask 77 && mkdir -p "` echo /tmp `"&& mkdir "` echo /tmp/ansible-tmp-1655277497.5041668-59502-107076550669567 `" && echo ansible-tmp-1655277497.5041668-59502-107076550669567="` echo /tmp/ansible-tmp-1655277497.5041668-59502-107076550669567 `" ) && sleep 0']
And I've got it!
In my simple-playbook.yaml
variable ansible-user
was redefined in vars
section and used as a label for the image. I removed it and ansible-bender
works fine now!
...
Image 'a-very-nice-image' was built successfully
I'm grateful for your help! Thank you!