Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Create Temporary Directory During Molecule Test Execution in Ansible Role #4170

Open
7 tasks done
SOHAN-cyber opened this issue Apr 22, 2024 · 2 comments
Open
7 tasks done

Comments

@SOHAN-cyber
Copy link

Prerequisites

  • This was not already reported in the past (duplicate check)
  • It does reproduce it with code from main branch (latest unreleased version)
  • I include a minimal example for reproducing the bug
  • The bug is not trivial, as for those a direct pull-request is preferred
  • Running pip check does not report any conflicts
  • I was able to reproduce the issue on a different machine
  • The issue is not specific to any driver other than 'default' one

Environment

molecule version

root@sohan:/home/aerohub/Documents/compegon/configuration-management/roles/cgi.example_app# molecule --version
INFO Found config file /home/aerohub/Documents/compegon/configuration-management/.config/molecule/config.yml
molecule 24.2.0 using python 3.10
ansible:2.16.2
azure:23.5.3 from molecule_plugins
containers:23.5.3 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
default:24.2.0 from molecule
docker:2.1.0 from molecule_docker requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
ec2:23.5.3 from molecule_plugins
gce:23.5.3 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
openstack:23.5.3 from molecule_plugins requiring collections: openstack.cloud>=2.1.0
podman:23.5.3 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
vagrant:23.5.3 from molecule_plugins

ansible --version 

root@sohan:/home/aerohub/Documents/compegon/configuration-management/roles/cgi.example_app# ansible --version
ansible [core 2.16.2]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /root/.local/lib/python3.10/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
jinja version = 3.0.3
libyaml = True

 cat /etc/os-release 

PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

What happened

While running the Molecule test cases for an Ansible role, users encounter an issue where Ansible fails to create a temporary directory. This issue hinders the completion of the test execution process. Despite attempts to resolve the problem by specifying a remote_tmp path, the problem persists.

Error:

fatal: [instance-docker]: 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-1713772767.4687226-114022-277068314687868 `" && echo ansible-tmp-1713772767.4687226-114022-277068314687868="` echo ~/.ansible/tmp/ansible-tmp-1713772767.4687226-114022-277068314687868 `" ), exited with result 1'
  unreachable: true

It is working fine when host is set to localhost.

Reproducing example

converge.yml

  • name: Converge
    hosts: all
    gather_facts: false

    pre_tasks:

    • name: Update apt cache if needed
      ansible.builtin.apt:
      update_cache: true
      cache_valid_time: 3600

    • name: Install required application apt packages
      ansible.builtin.apt:
      name: "{{ item }}"
      state: present
      with_items:

      • python3
      • python3-pip
      • virtualenv

    roles:

    • role: test.example_app
molecule.yml

driver:
name: docker
platforms:

  • name: instance-docker
    image: ubuntu:22.04
    command: ${MOLECULE_DOCKER_COMMAND:-""}
    pre_build_image: true # Use specified image as-is
main.yml

  • name: Create application directory
    ansible.builtin.file:
    path: "{{ example_app.dest_dir }}"
    state: directory
    mode: "0755"
    owner: "{{ example_app.user }}"
    group: "{{ example_app.group }}"

  • name: Clone application repo
    ansible.builtin.git:
    repo: "{{ example_app.app_repo }}"
    dest: "{{ example_app.dest_dir }}"
    accept_hostkey: true
    version: develop

  • name: Install dependencies
    ansible.builtin.pip:
    requirements: "{{ example_app.dest_dir }}/requirements.txt"
    virtualenv_python: python3
    virtualenv: "{{ example_app.dest_dir }}"

  • name: Install systemd service unit
    ansible.builtin.template:
    src: example_app.service.j2
    dest: /etc/systemd/system/example_app.service
    mode: "0644"
    become: true
    notify:

    • reload_systemd_daemon
    • restart_service
@mafalb
Copy link

mafalb commented Apr 22, 2024

It's a image running systemd?
See https://ansible.readthedocs.io/projects/molecule/guides/systemd-container/

or use systemd: always, that should also work IMO.
The reason for the error is IMO that you do not mount /tmp as tmpfs

name: instance-docker
image: ubuntu:22.04
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true # Use specified image as-is
systemd: always

@mafalb
Copy link

mafalb commented Apr 22, 2024

or use systemd: always, that should also work IMO.

I realise that you use docker, not podman. Maybe the systemd: always shortcut does only exist with podman.

@audgirka audgirka removed the new label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

3 participants