Molecule : basic documentation

1,032 views
Skip to first unread message

Sudheer S

unread,
Sep 18, 2022, 4:24:52 AM9/18/22
to Ansible Project

Hello,

I am trying to make a hello world type testing with Molecule. But it seems that the Molecule documentation is outdated.

https://molecule.readthedocs.io/en/latest/

https://molecule.readthedocs.io/en/latest/installation.html has instructions from Ubuntu 16.x. But not 20.x or 22.x.

"pip is the only supported installation method." - is this still true?

"It is highly recommended that you install molecule in a virtual environment." - is this still true?

Then the documentation goes on to talk about installing like this:

python3 -m pip install --user "molecule"

I followed the documentation further, created a new role:
molecule init role acme.my_new_role --driver-name docker

cd my_new_role/
cd molecule/default/

molecule test
CRITICAL 'molecule/default/molecule.yml' glob failed. Exiting.

give this error.


What steps did I miss or do wrongly?


I am willing to send a pull request to fix the documentation. But I need to know what are the recommended ways of installing molecule and working instructions to setup a new role and test with Molecule.

-

Sudheer

Michael Nelson

unread,
Sep 18, 2022, 8:20:26 AM9/18/22
to ansible...@googlegroups.com

Hi,

In my experience, the molecule commands need to be executed at the root of the role, therefore you should omit the second cd command:

cd my_new_role/

molecule test

should work

Regards,

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d4d16073-40e2-9549-5d18-05dbf8dcc95b%40sudheer.net.
--
Michael NELSON

Sudheer S

unread,
Sep 19, 2022, 12:55:28 AM9/19/22
to ansible...@googlegroups.com

I made some progress by adding a task in tasks.yml. It was empty before. Also edited molecule.yml.

tasks.main:

---
# tasks file for my_new_role
- name: install
  apt:
    name:
      - apache2
  update_cache: "yes"


molecule/default/molecule.yml:

---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: ubuntu
    image: geerlingguy/docker-ubuntu2204-ansible
    command: ${MOLECULE_DOCKER_COMMAND:-""}
    dockerfile: Dockerfile
    pre_build_image: false
    privileged: true
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
provisioner:
  name: ansible
verifier:
  name: ansible
lint: |
  set -e
  yamllint .
  ansible-lint .


molecule converge throws this error:



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

Where am I supposed to set this flag?

-

Sudheer

Michael Nelson

unread,
Sep 19, 2022, 6:27:32 AM9/19/22
to ansible...@googlegroups.com

Not sure why you need the other settings, but this works:


---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: ubuntu
    image: geerlingguy/docker-ubuntu2204-ansible

    privileged: true
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
provisioner:
  name: ansible
verifier:
  name: ansible
lint: |
  set -e
  yamllint .
  ansible-lint .

Regards,

Antuelle78

To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1fb6404b-c9f2-1dac-b5a6-2783706c1db2%40sudheer.net.
--
Michael NELSON
DevOPS/Systems Integration Engineer

Mobile: +33 751 05 24 68

cityscoot.eu

Sudheer S

unread,
Sep 19, 2022, 11:06:04 AM9/19/22
to ansible...@googlegroups.com

If that works for you, then something is probably wrong with my environment.

I have used the same file that you mention. I still get the same error as before.

Somehow, molecule and Ansible do not seem to correctly set privileges on the container.

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-1663599793.08011-676381-54041244190778 `\" && echo ansible-tmp-1663599793.08011-676381-54041244190778=\"` echo ~/.ansible/tmp/ansible-tmp-1663599793.08011-676381-54041244190778 `\


exited with result 1", "unreachable": true

-

Sudheer

Sudheer S

unread,
Sep 19, 2022, 1:42:30 PM9/19/22
to ansible...@googlegroups.com

Could you post your other files please?

I could use that to compare file or maybe run your files without changes and see what could be the issue.

Thanks.

-

Sudheer

On 19/09/22 15:57, Michael Nelson wrote:

Sudheer S

unread,
Sep 19, 2022, 1:57:06 PM9/19/22
to ansible...@googlegroups.com

I got it to work. The culprit was the `command`. I removed the line and it works now.

Thank you.

-

Sudheer

Reply all
Reply to author
Forward
0 new messages