molecule: "fatal: [instance]: UNREACHABLE! Failed to create temporary directory" within in role created by 'molecule init role'

Issue Type

  • Bug report

Molecule and Ansible details

ansible --version && molecule --version

ansible 2.10.7
  config file = None
  configured module search path = ['/home/bryant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/bryant/.pyenv/versions/vst-ansible-deployment/lib/python3.9/site-packages/ansible
  executable location = /home/bryant/.pyenv/versions/vst-ansible-deployment/bin/ansible
  python version = 3.9.1 (default, Feb 16 2021, 14:25:16) [GCC 9.3.0]

molecule 3.3.0 using python 3.9 
    ansible:2.10.7
    delegated:3.3.0 from molecule
    docker:0.2.4 from molecule_docker

Molecule installation method (one of):

  • pip (in a pyenv virtual environment)

Ansible installation method (one of):

  • pip (in a pyenv virtual environment)

Detail any linters or test runners used:

None.

Desired Behavior

Please give some details of the feature being requested or what should happen if providing a bug report.

I would like to be able to connect to the default molecule instance that is created, using the docker engine.

I have installed docker using the official doc, and my local user is member of the docker group.

I created a role using molecule init role and would like to run molecule converge with all the default settings only (later I will changed the docker image). I’ve also had this issue every time I’ve tried to use molecule on any role, even on entire playbooks, and on both Ubuntu 20.04 LTS desktop PopOS (current system) as well as a remote Ubuntu 20.02 LTS server.

I’ve tried molecule destroy as well as deleting my entire ~/.cache/molecule directory, as well as restarting docker.service, and putting remote_tmp = /tmp/ansible in my ansible.cfg, all with no change or resolution. I only have:

defaults]
inventory = inventory
vault_password_file = blah
host_key_checking = False
private_key_file = blah
callback_whitelist = ansible.posix.timer
remote_user = ubuntu

in my project’s ansible.cfg, and I’ve tried commenting out remote_user with no effect.

Actual Behaviour

Please give some details of what is actually happening. Include a minimum complete verifiable example with output of running molecule --debug.

molecule --debug converge
DEBUG    Validating schema /home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/molecule/default/molecule.yml.
INFO     default scenario test matrix: dependency, create, prepare, converge
INFO     Performing prerun...
WARNING  Computed fully qualified role name of redis_aws_init does not follow current galaxy requirements.
Please edit meta/main.yml and assure we can correctly determine full role name:

galaxy_info:
role_name: my_name  # if absent directory name hosting role is used instead
namespace: my_galaxy_namespace  # if absent, author is used instead

Namespace: https://galaxy.ansible.com/docs/contributing/namespaces.html#galaxy-namespace-limitations
Role: https://galaxy.ansible.com/docs/contributing/creating_role.html#role-names

As an alternative, you can add 'role-name' to either skip_list or warn_list.

INFO     Using ../../.cache/roles/redis_aws_init symlink to current repository in order to enable Ansible to find the role using its expected full name.
INFO     Added ANSIBLE_ROLES_PATH=~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:../../.cache/roles
INFO     Running default > dependency
WARNING  Skipping, missing the requirements file.
WARNING  Skipping, missing the requirements file.
INFO     Running default > create
WARNING  Skipping, instances already created.
INFO     Running default > prepare
WARNING  Skipping, prepare playbook not configured.
INFO     Running default > converge
INFO     Sanity checks: 'docker'
DEBUG: ANSIBLE ENVIRONMENT:
ANSIBLE_COLLECTIONS_PATH: /home/bryant/.cache/molecule/redis_aws_init/default/collections:/home/bryant/.ansible/collections:/usr/share/ansible/collections:/etc/ansible/collections
ANSIBLE_CONFIG: /home/bryant/.cache/molecule/redis_aws_init/default/ansible.cfg
ANSIBLE_FILTER_PLUGINS: /home/bryant/.pyenv/versions/vst-ansible-deployment/lib/python3.9/site-packages/molecule/provisioner/ansible/plugins/filter:/home/bryant/.cache/molecule/redis_aws_init/default/plugins/filter:/home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/plugins/filter:/home/bryant/.ansible/plugins/filter:/usr/share/ansible/plugins/filter
ANSIBLE_FORCE_COLOR: '1'
ANSIBLE_LIBRARY: /home/bryant/.pyenv/versions/vst-ansible-deployment/lib/python3.9/site-packages/molecule/provisioner/ansible/plugins/modules:/home/bryant/.cache/molecule/redis_aws_init/default/library:/home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/library:/home/bryant/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
ANSIBLE_ROLES_PATH: /home/bryant/.cache/molecule/redis_aws_init/default/roles:/home/bryant/src/api_guys/ansible-deploy-vst/roles:/home/bryant/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:../../.cache/roles

DEBUG: MOLECULE ENVIRONMENT:
MOLECULE_DEBUG: 'True'
MOLECULE_DEPENDENCY_NAME: galaxy
MOLECULE_DRIVER_NAME: docker
MOLECULE_ENV_FILE: /home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/.env.yml
MOLECULE_EPHEMERAL_DIRECTORY: /home/bryant/.cache/molecule/redis_aws_init/default
MOLECULE_FILE: /home/bryant/.cache/molecule/redis_aws_init/default/molecule.yml
MOLECULE_INSTANCE_CONFIG: /home/bryant/.cache/molecule/redis_aws_init/default/instance_config.yml
MOLECULE_INVENTORY_FILE: /home/bryant/.cache/molecule/redis_aws_init/default/inventory/ansible_inventory.yml
MOLECULE_PROJECT_DIRECTORY: /home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init
MOLECULE_PROVISIONER_NAME: ansible
MOLECULE_SCENARIO_DIRECTORY: /home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/molecule/default
MOLECULE_SCENARIO_NAME: default
MOLECULE_STATE_FILE: /home/bryant/.cache/molecule/redis_aws_init/default/state.yml
MOLECULE_VERIFIER_NAME: ansible
MOLECULE_VERIFIER_TEST_DIRECTORY: /home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/molecule/default/tests

DEBUG: SHELL REPLAY:
ANSIBLE_COLLECTIONS_PATH=/home/bryant/.cache/molecule/redis_aws_init/default/collections:/home/bryant/.ansible/collections:/usr/share/ansible/collections:/etc/ansible/collections ANSIBLE_CONFIG=/home/bryant/.cache/molecule/redis_aws_init/default/ansible.cfg ANSIBLE_FILTER_PLUGINS=/home/bryant/.pyenv/versions/vst-ansible-deployment/lib/python3.9/site-packages/molecule/provisioner/ansible/plugins/filter:/home/bryant/.cache/molecule/redis_aws_init/default/plugins/filter:/home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/plugins/filter:/home/bryant/.ansible/plugins/filter:/usr/share/ansible/plugins/filter ANSIBLE_FORCE_COLOR=1 ANSIBLE_LIBRARY=/home/bryant/.pyenv/versions/vst-ansible-deployment/lib/python3.9/site-packages/molecule/provisioner/ansible/plugins/modules:/home/bryant/.cache/molecule/redis_aws_init/default/library:/home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/library:/home/bryant/.ansible/plugins/modules:/usr/share/ansible/plugins/modules ANSIBLE_ROLES_PATH=/home/bryant/.cache/molecule/redis_aws_init/default/roles:/home/bryant/src/api_guys/ansible-deploy-vst/roles:/home/bryant/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:../../.cache/roles MOLECULE_DEBUG=True MOLECULE_DEPENDENCY_NAME=galaxy MOLECULE_DRIVER_NAME=docker MOLECULE_ENV_FILE=/home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/.env.yml MOLECULE_EPHEMERAL_DIRECTORY=/home/bryant/.cache/molecule/redis_aws_init/default MOLECULE_FILE=/home/bryant/.cache/molecule/redis_aws_init/default/molecule.yml MOLECULE_INSTANCE_CONFIG=/home/bryant/.cache/molecule/redis_aws_init/default/instance_config.yml MOLECULE_INVENTORY_FILE=/home/bryant/.cache/molecule/redis_aws_init/default/inventory/ansible_inventory.yml MOLECULE_PROJECT_DIRECTORY=/home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init MOLECULE_PROVISIONER_NAME=ansible MOLECULE_SCENARIO_DIRECTORY=/home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/molecule/default MOLECULE_SCENARIO_NAME=default MOLECULE_STATE_FILE=/home/bryant/.cache/molecule/redis_aws_init/default/state.yml MOLECULE_VERIFIER_NAME=ansible MOLECULE_VERIFIER_TEST_DIRECTORY=/home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/molecule/default/tests

COMMAND: ansible-playbook --diff --inventory /home/bryant/.cache/molecule/redis_aws_init/default/inventory --skip-tags molecule-notest,notest /home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/molecule/default/converge.yml

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

TASK [Gathering Facts] *********************************************************
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-1618876867.7336655-2529030-224654731083847 `\" && echo ansible-tmp-1618876867.7336655-2529030-224654731083847=\"` echo ~/.ansible/tmp/ansible-tmp-1618876867.7336655-2529030-224654731083847 `\" ), exited with result 1", "unreachable": true}

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

CRITICAL Ansible return code was 4, command was: ansible-playbook --diff --inventory /home/bryant/.cache/molecule/redis_aws_init/default/inventory --skip-tags molecule-notest,notest /home/bryant/src/api_guys/ansible-deploy-vst/roles/redis_aws_init/molecule/default/converge.yml

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 21 (3 by maintainers)

Most upvoted comments

Hi guys, if someone else is struggling with this, deleting the default create.yml playbook resolved my problems. I do not know why and i do not care why.

Jut an FYI I found this happens to me when I have a bad state, either I’ve restarted or Docker has crashed (macOS). The remedy has been to do:

molecule destroy

This file never existed for me, I don’t think it’s the root cause

Problem in the current Ubuntu I can confirm, plain install ran this from scratch and same problem.
ubuntu-22 amd64 docker-desktop Ran every suggested fix, nothing works.

Jut an FYI I found this happens to me when I have a bad state, either I’ve restarted or Docker has crashed (macOS). The remedy has been to do:

molecule destroy

This helped solve my issue, thank you

I solved that issue by changing the volume mount from - /sys/fs/cgroup:/sys/fs/cgroup:ro to - /sys/fs/cgroup:/sys/fs/cgroup:rw and adding cgroupns_mode: host

For ubuntu-2204(in which cgroup v2 is used by default), could you try the workaround in this PR? zhan9san/ansible-role-jenkins#14 (files)

Adding cgroupns_mode: host to every platform in molecule.yml seems to pretty reliably solve this error for me!

@theko2fi @cy8aer @bkowenswork

For ubuntu-2204(in which cgroup v2 is used by default), could you try the workaround in this PR? https://github.com/zhan9san/ansible-role-jenkins/pull/14/files


@life5ign @rvanmarkus

For MacOS, I cannot reproduce the issue. Could you try again?


Here is my test on MacOS

Test environment

❯ python3 -m pip freeze | grep -E 'molecule|ansible'
ansible==5.7.1
ansible-compat==2.2.4
ansible-core==2.12.10
ansible-lint==6.16.2
molecule==5.0.1
molecule-plugins==23.4.1

Create a new role

❯ molecule init role -d docker acme.my_role_x
INFO     Initializing new role my_role_x...
No config file found; using defaults
- Role my_role_x was created successfully
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | CHANGED => {"backup": "","changed": true,"msg": "line added"}
INFO     Initialized role in /Users/jackzhang/src/tmp/my_role_x successfully.

Run test

❯ cd my_role_x
~/src/tmp/my_role_x                                                                                                   00:13:24
❯ molecule converge
WARNING  The scenario config file ('/Users/jackzhang/src/tmp/my_role_x/molecule/default/molecule.yml') has been modified since the scenario was created. If recent changes are important, reset the scenario with 'molecule destroy' to clean up created items or 'molecule reset' to clear current configuration.
WARNING  Driver docker does not provide a schema.
INFO     default scenario test matrix: dependency, create, prepare, converge
INFO     Performing prerun with role_name_check=0...
INFO     Set ANSIBLE_LIBRARY=/Users/jackzhang/.cache/ansible-compat/aa989b/modules:/Users/jackzhang/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/Users/jackzhang/.cache/ansible-compat/aa989b/collections:/Users/jackzhang/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/Users/jackzhang/.cache/ansible-compat/aa989b/roles:/Users/jackzhang/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Using /Users/jackzhang/.cache/ansible-compat/aa989b/roles/acme.my_role_x symlink to current repository in order to enable Ansible to find the role using its expected full name.
INFO     Running default > dependency
WARNING  Skipping, missing the requirements file.
WARNING  Skipping, missing the requirements file.
INFO     Running default > create
INFO     Sanity checks: 'docker'

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

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

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

TASK [Check presence of custom Dockerfiles] ************************************
ok: [localhost] => (item={'image': 'quay.io/centos/centos:stream8', 'name': 'instance', 'pre_build_image': True})

TASK [Create Dockerfiles from image names] *************************************
skipping: [localhost] => (item={'image': 'quay.io/centos/centos:stream8', 'name': 'instance', 'pre_build_image': True})

TASK [Synchronization the context] *********************************************
skipping: [localhost] => (item={'image': 'quay.io/centos/centos:stream8', 'name': 'instance', 'pre_build_image': True})

TASK [Discover local Docker images] ********************************************
ok: [localhost] => (item={'changed': False, 'skipped': True, 'skip_reason': 'Conditional result was False', 'item': {'image': 'quay.io/centos/centos:stream8', 'name': 'instance', 'pre_build_image': True}, 'ansible_loop_var': 'item', 'i': 0, 'ansible_index_var': 'i'})

TASK [Build an Ansible compatible image (new)] *********************************
skipping: [localhost] => (item=molecule_local/quay.io/centos/centos:stream8)

TASK [Create docker network(s)] ************************************************

TASK [Determine the CMD directives] ********************************************
ok: [localhost] => (item={'image': 'quay.io/centos/centos:stream8', 'name': 'instance', 'pre_build_image': True})

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

TASK [Wait for instance(s) creation to complete] *******************************
FAILED - RETRYING: [localhost]: Wait for instance(s) creation to complete (300 retries left).
changed: [localhost] => (item={'failed': 0, 'started': 1, 'finished': 0, 'ansible_job_id': '588603042191.77157', 'results_file': '/Users/jackzhang/.ansible_async/588603042191.77157', 'changed': True, 'item': {'image': 'quay.io/centos/centos:stream8', 'name': 'instance', 'pre_build_image': True}, 'ansible_loop_var': 'item'})

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

INFO     Running default > prepare
WARNING  Skipping, prepare playbook not configured.
INFO     Running default > converge

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

TASK [Gathering Facts] *********************************************************
ok: [instance]

TASK [Include acme.my_role_x] **************************************************

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

I have not touched Ansible or Molecule for more than a year now (switched jobs and stopped using that stuff), so I am not really the best person to judge if this last error is caused by the same error as the original one. In the original report, Ansible reported that the test instance is not reachable, so all that “cannot create tmp directory” error message was irrelevant since there was no instance to operate on. But all of the follow-up responses omit this information, so there is no way to tell what exactly is broken.

I would advice you to open a new issue if the instance is reachable since this is a different issue compared to the one described here.

I can replicate this on Ubuntu 20. Same issue as @RickS-C137

@tadeboro Please considering re-opening.

I keep getting this error quite often. A molecule destroy doesn’t help, wether with or without --all. Neither does a restart of Docker-Desktop. Running docker ps -a directly afterwards shows no running containers. I also tried invoking the whole command: umask 77 && mkdir -p \"`` echo /tmp/.ansible ``\"&& mkdir \"`` echo /tmp/.ansible/ansible-tmp-1674051067.731343-66889-65569499472235 ``\" && echo ansible-tmp-1674051067.731343-66889-65569499472235=\"`` echo /tmp/.ansible/ansible-tmp-1674051067.731343-66889-65569499472235 ``\" which put’s out: mkdir: "/tmp/.ansible: No such file or directory.

So I started to split it up. umask 77 && mkdir -p \"`` echo /tmp/.ansible ``\" seems to works.

umask 77 && mkdir -p \"`` echo /tmp/.ansible ``\"&& mkdir \"`` echo /tmp/.ansible/ansible-tmp-1674051067.731343-66889-65569499472235 ``\" does NOT work.

So the issue is with mkdir "` echo /tmp/.ansible/ansible-tmp-1674051067.731343-66889-65569499472235 `"

/tmp/.ansible exists with 777.

After a while it works again.

I’m using MacOS 13.1 And here’s the output of molecule --version: molecule --version molecule 4.0.4 using python 3.11 ansible:2.14.1 delegated:4.0.4 from molecule docker:2.1.0 from molecule_docker requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0 vagrant:1.0.0 from molecule_vagrant

Sorry for the double backticks in the commands, didn’t get editor to escape them correctly.

Jut an FYI I found this happens to me when I have a bad state, either I’ve restarted or Docker has crashed (macOS). The remedy has been to do:

molecule destroy

Good idea! When this doesn’t work, I’ve found molecule destroy --all to be helpful. But make sure you’re okay with destroying everything first 😃