ansible / molecule

Molecule aids in the development and testing of Ansible content: collections, playbooks and roles
https://ansible.readthedocs.io/projects/molecule/
MIT License
3.89k stars 664 forks source link

Failed to create temporary directory #3818

Open mabed-fr opened 1 year ago

mabed-fr commented 1 year ago

Issue Type

Molecule and Ansible details

ansible --version && molecule --version
ansible [core 2.14.1]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/.local/share/virtualenvs/ansible_netdata-Np7YJUAj/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /root/.local/share/virtualenvs/ansible_netdata-Np7YJUAj/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/root/.local/share/virtualenvs/ansible_netdata-Np7YJUAj/bin/python)
  jinja version = 3.1.2
  libyaml = True
molecule 4.0.4 using python 3.9 
    ansible:2.14.1
    azure:23.0.0 from molecule_plugins
    containers:23.0.0 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
    delegated:4.0.4 from molecule
    docker:23.0.0 from molecule_plugins requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
    ec2:23.0.0 from molecule_plugins
    gce:23.0.0 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
    podman:23.0.0 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
    vagrant:23.0.0 from molecule_plugins

Molecule installation method (one of):

Ansible installation method (one of):

Detail any linters or test runners used:

Actual Behaviour

PLAY [Prepare] *****

TASK [Gathering Facts] *********************************************************
fatal: [bookworm]: 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 ~/.ansible/tmp `\"&& mkdir \"` echo ~/.ansible/tmp/ansible-tmp-1674825123.6768813-82852-281344622743994 `\" && echo ansible-tmp-1674825123.6768813-82852-281344622743994=\"` echo ~/.ansible/tmp/ansible-tmp-1674825123.6768813-82852-281344622743994 `\" ), exited with result 1", "unreachable": true}
fatal: [bullseye]: 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 ~/.ansible/tmp `\"&& mkdir \"` echo ~/.ansible/tmp/ansible-tmp-1674825123.6879113-82853-251487814663029 `\" && echo ansible-tmp-1674825123.6879113-82853-251487814663029=\"` echo ~/.ansible/tmp/ansible-tmp-1674825123.6879113-82853-251487814663029 `\" ), exited with result 1", "unreachable": true}
fatal: [buster]: 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 ~/.ansible/tmp `\"&& mkdir \"` echo ~/.ansible/tmp/ansible-tmp-1674825123.7105093-82854-194659650698251 `\" && echo ansible-tmp-1674825123.7105093-82854-194659650698251=\"` echo ~/.ansible/tmp/ansible-tmp-1674825123.7105093-82854-194659650698251 `\" ), exited with result 1", "unreachable": true}

rm -rf /root/.cache/molecule

mabed-fr commented 1 year ago
ansible --version && molecule --version
ansible [core 2.14.1]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/.local/share/virtualenvs/ansible_netdata-Np7YJUAj/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /root/.local/share/virtualenvs/ansible_netdata-Np7YJUAj/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/root/.local/share/virtualenvs/ansible_netdata-Np7YJUAj/bin/python)
  jinja version = 3.1.2
  libyaml = True
molecule 4.0.4 using python 3.9 
    ansible:2.14.1
    azure:23.0.0 from molecule_plugins
    containers:23.0.0 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
    delegated:4.0.4 from molecule
    docker:23.0.0 from molecule_plugins requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
    ec2:23.0.0 from molecule_plugins
    gce:23.0.0 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
    podman:23.0.0 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
    vagrant:23.0.0 from molecule_plugins
02:14:58 (ansible_netdata-Np7YJUAj) root@SRV-MABED ansible_netdata ±|main ✗|→ molecule reset
INFO     default scenario test matrix: 
INFO     Performing prerun with role_name_check=0...
INFO     Set ANSIBLE_LIBRARY=/root/.cache/ansible-compat/a3b642/modules:/root/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/root/.cache/ansible-compat/a3b642/collections:/root/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/root/.cache/ansible-compat/a3b642/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Using /root/.cache/ansible-compat/a3b642/roles/mabed.netdata symlink to current repository in order to enable Ansible to find the role using its expected full name.
INFO     Removing /root/.cache/molecule/ansible_netdata/default
INFO     Deleted container fc2cf8faeb325eba5fd21fdee0c8117bb2b3371c40a82336001f8ee9d88a4a43
INFO     Deleted container 27cbe89cd70849098c47a2bebc1e710ad8f853d4dd42b87e0ad2307c361506ac
INFO     Deleted container bb53852b6595c90e7a6db4ec1a8cdcb660e36e37f6599c114432dff9124e5831
02:16:13 (ansible_netdata-Np7YJUAj) root@SRV-MABED ansible_netdata ±|main ✗|→ molecule test
INFO     default scenario test matrix: lint, destroy, dependency, syntax, create, converge, idempotence, check, side_effect, verify, destroy
INFO     Performing prerun with role_name_check=0...
INFO     Set ANSIBLE_LIBRARY=/root/.cache/ansible-compat/a3b642/modules:/root/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/root/.cache/ansible-compat/a3b642/collections:/root/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/root/.cache/ansible-compat/a3b642/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Using /root/.cache/ansible-compat/a3b642/roles/mabed.netdata symlink to current repository in order to enable Ansible to find the role using its expected full name.
INFO     Running default > lint
INFO     Set ANSIBLE_LIBRARY=/root/.cache/ansible-compat/a3b642/modules:/root/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/root/.cache/ansible-compat/a3b642/collections:/root/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/root/.cache/ansible-compat/a3b642/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Using /root/.cache/ansible-compat/a3b642/roles/mabed.netdata symlink to current repository in order to enable Ansible to find the role using its expected full name.
INFO     Discovered files to lint using: git -c safe.directory=/opt/git/ansible_netdata ls-files --cached --others --exclude-standard -z
INFO     Excluded removed files using: git -c safe.directory=/opt/git/ansible_netdata ls-files --deleted -z
INFO     Executing syntax check on molecule/default/converge.yml (0.82s)
INFO     Executing syntax check on molecule/default/prepare.yml (1.14s)
INFO     Executing syntax check on molecule/default/verify.yml (1.18s)

Passed with production profile: 0 failure(s), 0 warning(s) on 22 files.
INFO     Running default > destroy
INFO     Sanity checks: 'docker'

PLAY [Destroy] *****************************************************************

TASK [Set async_dir for HOME env] **********************************************
ok: [localhost]

TASK [Destroy molecule instance(s)] ********************************************
changed: [localhost] => (item=bullseye)
changed: [localhost] => (item=buster)
changed: [localhost] => (item=bookworm)

TASK [Wait for instance(s) deletion to complete] *******************************
ok: [localhost] => (item=bullseye)
ok: [localhost] => (item=buster)
ok: [localhost] => (item=bookworm)

TASK [Delete docker networks(s)] ***********************************************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

INFO     Running default > dependency
WARNING  Skipping, missing the requirements file.
WARNING  Skipping, missing the requirements file.
INFO     Running default > syntax

playbook: /opt/git/ansible_netdata/molecule/default/converge.yml
INFO     Running default > create

PLAY [Create] ******************************************************************

TASK [Set async_dir for HOME env] **********************************************
ok: [localhost]

TASK [Log into a Docker registry] **********************************************
skipping: [localhost] => (item=None) 
skipping: [localhost] => (item=None) 
skipping: [localhost] => (item=None) 
skipping: [localhost]

TASK [Check presence of custom Dockerfiles] ************************************
ok: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:bullseye', 'name': 'bullseye', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})
ok: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:buster', 'name': 'buster', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})
ok: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:bookworm', 'name': 'bookworm', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})

TASK [Create Dockerfiles from image names] *************************************
skipping: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:bullseye', 'name': 'bullseye', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})
skipping: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:buster', 'name': 'buster', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})
skipping: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:bookworm', 'name': 'bookworm', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})
skipping: [localhost]

TASK [Synchronization the context] *********************************************
skipping: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:bullseye', 'name': 'bullseye', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})
skipping: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:buster', 'name': 'buster', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})
skipping: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:bookworm', 'name': 'bookworm', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})
skipping: [localhost]

TASK [Discover local Docker images] ********************************************
ok: [localhost] => (item={'changed': False, 'skipped': True, 'skip_reason': 'Conditional result was False', 'item': {'image': 'docker.io/buluma/debian-systemd:bullseye', 'name': 'bullseye', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True}, 'ansible_loop_var': 'item', 'i': 0, 'ansible_index_var': 'i'})
ok: [localhost] => (item={'changed': False, 'skipped': True, 'skip_reason': 'Conditional result was False', 'item': {'image': 'docker.io/buluma/debian-systemd:buster', 'name': 'buster', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True}, 'ansible_loop_var': 'item', 'i': 1, 'ansible_index_var': 'i'})
ok: [localhost] => (item={'changed': False, 'skipped': True, 'skip_reason': 'Conditional result was False', 'item': {'image': 'docker.io/buluma/debian-systemd:bookworm', 'name': 'bookworm', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True}, 'ansible_loop_var': 'item', 'i': 2, 'ansible_index_var': 'i'})

TASK [Build an Ansible compatible image (new)] *********************************
skipping: [localhost] => (item=molecule_local/docker.io/buluma/debian-systemd:bullseye) 
skipping: [localhost] => (item=molecule_local/docker.io/buluma/debian-systemd:buster) 
skipping: [localhost] => (item=molecule_local/docker.io/buluma/debian-systemd:bookworm) 
skipping: [localhost]

TASK [Create docker network(s)] ************************************************
skipping: [localhost]

TASK [Determine the CMD directives] ********************************************
skipping: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:bullseye', 'name': 'bullseye', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})
skipping: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:buster', 'name': 'buster', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})
skipping: [localhost] => (item={'image': 'docker.io/buluma/debian-systemd:bookworm', 'name': 'bookworm', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True})
skipping: [localhost]

TASK [Create molecule instance(s)] *********************************************
changed: [localhost] => (item=bullseye)
changed: [localhost] => (item=buster)
changed: [localhost] => (item=bookworm)

TASK [Wait for instance(s) creation to complete] *******************************
changed: [localhost] => (item={'failed': 0, 'started': 1, 'finished': 0, 'ansible_job_id': '650051690242.86703', 'results_file': '/root/.ansible_async/650051690242.86703', 'changed': True, 'item': {'image': 'docker.io/buluma/debian-systemd:bullseye', 'name': 'bullseye', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True}, 'ansible_loop_var': 'item'})
changed: [localhost] => (item={'failed': 0, 'started': 1, 'finished': 0, 'ansible_job_id': '718513813088.86746', 'results_file': '/root/.ansible_async/718513813088.86746', 'changed': True, 'item': {'image': 'docker.io/buluma/debian-systemd:buster', 'name': 'buster', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True}, 'ansible_loop_var': 'item'})
changed: [localhost] => (item={'failed': 0, 'started': 1, 'finished': 0, 'ansible_job_id': '472546529818.86932', 'results_file': '/root/.ansible_async/472546529818.86932', 'changed': True, 'item': {'image': 'docker.io/buluma/debian-systemd:bookworm', 'name': 'bookworm', 'override_command': False, 'pre_build_image': True, 'privileged': True, 'systemd': True, 'tty': True}, 'ansible_loop_var': 'item'})

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=2    unreachable=0    failed=0    skipped=6    rescued=0    ignored=0

INFO     Running default > converge

PLAY [Converge] ****************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [buster]: 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 ~/.ansible/tmp `\"&& mkdir \"` echo ~/.ansible/tmp/ansible-tmp-1674825402.427584-87201-88261232286722 `\" && echo ansible-tmp-1674825402.427584-87201-88261232286722=\"` echo ~/.ansible/tmp/ansible-tmp-1674825402.427584-87201-88261232286722 `\" ), exited with result 1", "unreachable": true}
fatal: [bookworm]: 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 ~/.ansible/tmp `\"&& mkdir \"` echo ~/.ansible/tmp/ansible-tmp-1674825402.4381928-87199-197140126513681 `\" && echo ansible-tmp-1674825402.4381928-87199-197140126513681=\"` echo ~/.ansible/tmp/ansible-tmp-1674825402.4381928-87199-197140126513681 `\" ), exited with result 1", "unreachable": true}
fatal: [bullseye]: 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 ~/.ansible/tmp `\"&& mkdir \"` echo ~/.ansible/tmp/ansible-tmp-1674825402.4450128-87200-166504053599169 `\" && echo ansible-tmp-1674825402.4450128-87200-166504053599169=\"` echo ~/.ansible/tmp/ansible-tmp-1674825402.4450128-87200-166504053599169 `\" ), exited with result 1", "unreachable": true}

PLAY RECAP *********************************************************************
bookworm                   : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0
bullseye                   : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0
buster                     : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0

WARNING  Retrying execution failure 4 of: ansible-playbook --inventory /root/.cache/molecule/ansible_netdata/default/inventory --skip-tags molecule-notest,notest /opt/git/ansible_netdata/molecule/default/converge.yml
CRITICAL Ansible return code was 4, command was: ['ansible-playbook', '--inventory', '/root/.cache/molecule/ansible_netdata/default/inventory', '--skip-tags', 'molecule-notest,notest', '/opt/git/ansible_netdata/molecule/default/converge.yml']
WARNING  An error occurred during the test sequence action: 'converge'. Cleaning up.
INFO     Running default > cleanup
WARNING  Skipping, cleanup playbook not configured.
INFO     Running default > destroy

PLAY [Destroy] *****************************************************************

TASK [Set async_dir for HOME env] **********************************************
ok: [localhost]

TASK [Destroy molecule instance(s)] ********************************************
changed: [localhost] => (item=bullseye)
changed: [localhost] => (item=buster)
changed: [localhost] => (item=bookworm)

TASK [Wait for instance(s) deletion to complete] *******************************
changed: [localhost] => (item=bullseye)
changed: [localhost] => (item=buster)
changed: [localhost] => (item=bookworm)

TASK [Delete docker networks(s)] ***********************************************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0
javanaut-de commented 1 year ago

This occurs for me with a ~ 10% probability when running role tests with Jenkins on a number of worker nodes using the podman driver and different OS images. Could this be some timing problem like container is not ready up when trying to access? Current workaround is to repeat failed tests a couple of times, which "works" most times as the error does not seem to depend on either the used OS image, worker node, scenario or time of the day.

Also this annoys hell out of me as I try to find a cause or solution for a couple of weeks now.

Edit:

Worker host OS:

Ubuntu 20.04

Linux 5.15.0-60-generic #66~20.04.1-Ubuntu SMP Wed Jan 25 09:41:30 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Versions used:

podman version 3.4.2
Python 3.11.2
ansible [core 2.14.3]
molecule 4.0.4 using python 3.11 
    [...]
    podman:23.0.0 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0

Example of failing step:

PLAY [Converge] ****************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [setup-ubuntu22-novendor-msu]: 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-1677570718.4433966-259791-13971188385784 `\" && echo ansible-tmp-1677570718.4433966-259791-13971188385784=\"` echo /tmp/ansible-tmp-1677570718.4433966-259791-13971188385784 `\" ), exited with result 255", "unreachable": true}

Interestingly the error message suggests using a remote temp path rooted in /tmp which is obviously already the case?

Corresponding section in the molecule.yml files:

provisioner:
  name: ansible
  env:
    ANSIBLE_LOCAL_TEMP: "${WORKSPACE:-$HOME}/.ansible/tmp"
    ANSIBLE_REMOTE_TMP: /tmp
javanaut-de commented 1 year ago

Finally, after switching to a set of static built executables of podman and its dependencies the issue seems having stopped to appear (for now ...)

kennethacurtis commented 1 year ago

@javanaut-de can you further explain what you did to fix the issue?

atj commented 1 year ago

I was running into this issue on a new role when invoking Molecule via GitHub Actions. Turned out I had accidentally copied in an old version of molecule.yml from another role which was missing a couple of platforms options:

platforms:
  - name: instance
    image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest"
    command: ${MOLECULE_DOCKER_COMMAND:-""}
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    privileged: true
    pre_build_image: true

Changing the cgroup volume to rw and adding cgroupns_mode: host resolved the issue for me:

platforms:
  - name: instance
    image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest"
    command: ${MOLECULE_DOCKER_COMMAND:-""}
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
    cgroupns_mode: host
    privileged: true
    pre_build_image: true
calillo commented 1 year ago

I have similar issue on Mac (but also on Windows it's the same) when running molecule inside container (with Docker Desktop). After spending a lot of time trying downgrading versions I realized that the cause was to be found elsewhere and found it in Docker Desktop, in fact natively on Mac (or on the Windows WSL) it worked perfectly. At first, the reasoning was not clear to me but after reading some kernel intuition I realized it could be something like this. In fact months ago everything works and at some point it stopped and returning the error "failed to resolve remote temporary directory ... returned empty string" From here I found out that since Docker Desktop 4.13 they upgraded the kernel from 5.10.x to 5.15.x and this is the root cause. Downgrading Docker Desktop to 4.12 on both Mac and Windows everything started working again. I think this problem also exists on a Linux distribution with a kernel 5.15.x, I can't tell if it's an incompatibility between ansible/molecule and the kernel. I hope someone fix this issue.

Frzk commented 1 year ago

I noticed something interesting in the documentation, here: https://ansible.readthedocs.io/projects/molecule/docker/#create-playbook :

# we want to avoid errors like "Failed to create temporary directory"
- name: Validate that inventory was refreshed
  hosts: molecule
  gather_facts: false
  tasks:
    - name: Check uname
      ansible.builtin.raw: uname -a
      register: result
      changed_when: false

    - name: Display uname info
      ansible.builtin.debug:
        msg: "{{ result.stdout }}"

How do these tasks prevent the "Failed to create temporary directory" error? Would it be possible for someone to elaborate a bit please? 🙏

bataliero commented 1 year ago

I have the same error message:

fatal: [instance]: 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 ~/.ansible/tmp `\"&& mkdir \"` echo ~/.ansible/tmp/ansible-tmp-1698921867.2522438-37545-235208512047875 `\" && echo ansible-tmp-1698921867.2522438-37545-235208512047875=\"` echo ~/.ansible/tmp/ansible-tmp-1698921867.2522438-37545-235208512047875 `\" ), exited with result 1", "unreachable": true}

versions:

ansible [core 2.15.5]
  config file = None
  configured module search path = ['/home/mynia/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mynia/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/mynia/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/mynia/.local/bin/ansible
  python version = 3.10.13 (main, Aug 25 2023, 13:20:03) [GCC 9.4.0] (/usr/bin/python3.10)
  jinja version = 3.1.2
  libyaml = False
molecule 6.0.2 using python 3.10
    ansible:2.15.5
    azure:23.5.0 from molecule_plugins
    containers:23.5.0 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
    default:6.0.2 from molecule
    docker:23.5.0 from molecule_plugins requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
    ec2:23.5.0 from molecule_plugins
    gce:23.5.0 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
    podman:23.5.0 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
    vagrant:23.5.0 from molecule_plugins

OS -Linux Mint :

Distributor ID: Linuxmint
Description:    Linux Mint 20.3
Release:        20.3
Codename:       una
  1. molecule test does not work if I use podman as a driver, and it does not work with docker as well
  2. molecule destroy does no help
  3. Changing molecule.yaml - cgroup volume to rw and adding cgroupns_mode: host does not help

Any other ideas?

deekayen commented 12 months ago
# we want to avoid errors like "Failed to create temporary directory"
- name: Validate that inventory was refreshed
  hosts: molecule
  gather_facts: false

How do these tasks prevent the "Failed to create temporary directory" error? Would it be possible for someone to elaborate a bit please? 🙏

It was the gather_facts: false in converge.yml that fixed this error in my situation, but then also broke places where I was using the facts in the role.

When I tried to do ansible.builtin.setup instead, it gave the error specifically on that task instead. Setting an env or config_options in the provisioner stanza for a remote /tmp path hasn't worked yet.

waterkip commented 10 months ago

I have the same error, but ONLY if I have command: in the molecule/default/molecule.yml. When this isn't there I don't get the error. Although other errors occur at that point in relation to systems.

Edit: The bug disappears when I replace volume_mounts with volumes, the following just works..

platforms:
  - name: debian-testing
    image: geerlingguy/docker-debian12-ansible
    privileged: true
    pre_build_image: true
    cgroupns_mode: host
    command: ""
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
      - /run
      - /run/lock
Nurlan199206 commented 9 months ago

help me pls too, i got same issue

TASK [community.docker.docker_container_exec] **********************************
fatal: [instance]: 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 ~/.ansible/tmp `\"&& mkdir \"` echo ~/.ansible/tmp/ansible-tmp-1705739384.2542112-6117-205789851287293 `\" && echo ansible-tmp-1705739384.2542112-6117-205789851287293=\"` echo ~/.ansible/tmp/ansible-tmp-1705739384.2542112-6117-205789851287293 `\" ), exited with result 1", "unreachable": true}
cat converge.yml
---
- name: Converge
  hosts: all
  gather_facts: false
  tasks:
    - name: Replace this task with one that validates your content
      ansible.builtin.debug:
        msg: "This is the effective test"

    - community.docker.docker_container_exec:
       container: hello-world
       command: df
sdarwin commented 6 months ago

I was just updating multiple roles. an earlier molecule.yml functioned on many of them:

platforms:
  - name: instance
    image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
    command: ${MOLECULE_DOCKER_COMMAND:-""}
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
      - /var/lib/docker
    privileged: true
    pre_build_image: true

then hit this "failed to create temporary directory" for one repo. why only one repo? It required the suggested update:

(unless the issue occurs 'randomly', in which case the fix was accidental)

platforms:
  - name: instance
    image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest"
    command: ${MOLECULE_DOCKER_COMMAND:-""}
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
    cgroupns_mode: host
    privileged: true
    pre_build_image: true

Edit: This update is discussed in https://www.jeffgeerling.com/blog/2022/docker-and-systemd-getting-rid-dreaded-failed-connect-bus-error "Docker recently switched from cgroups v1 to cgroups v2".

cschindlbeck commented 5 months ago

This fix by @sdarwin does work on Ubuntu20.04, Ubuntu22.04, so close this issue?

Edit: One minor thing, pre_build_image is not found by community.docker.docker_container but for me it worked without it :smile:

taylor-schneider commented 4 months ago

I am seeing the same issue on almalinux 9.2

mostwanted7 commented 3 months ago

Still seeing the same issue, tried every proposed solution but no luck.

turb0bur commented 2 months ago

Try removing the create.yml file located in the same folder as your molecule.yml file. It helped me. From what I understand, it contains an old workaround for gathering facts. I found this solution here.