molecule: Failed to create temporary directory

Issue Type

  • Bug report

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):

  • pip

Ansible installation method (one of):

  • pip

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

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 11
  • Comments: 18

Commits related to this issue

Most upvoted comments

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

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

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.

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”.

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