I am new to using molecule and ansible. I am trying to follow this guide: https://molecule.readthedocs.io/en/latest/getting-started.html#getting-started-guide
The problem I have is that when I run ...
(venv) [red@mac-laptop.local fake_role]$ molecule test
... I get this error ...
... lots of output ...
INFO Running default > prepare
WARNING Skipping, prepare playbook not configured.
INFO Running default > converge
PLAY [Converge] ****************************************************************
TASK [Include fake_role] *******************************************************
TASK [fake_role : fake_role | Create /tmp/fake] ********************************
fatal: [instance]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname instance: nodename nor servname provided, or not known", "unreachable": true}
PLAY RECAP *********************************************************************
instance : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
... a lot more output ...
UPDATE:
The error goes away if I add instance
to my /etc/hosts
file like so:
(venv) [red@mac-laptop.local fake_role]$ grep instance /etc/hosts
127.0.0.1 instance
But the /tmp/fake
dir that my fake_role
creates gets created on my laptop and not in the docker container molecule is supposed to use.
UPDATE II:
Here is my current molecule.yml
file. I had not correctly set up the "platforms" section:
---
dependency:
name: galaxy
driver:
name: docker
# platforms:
# - name: instance
platforms:
- name: instance
image: docker.io/pycontribs/centos:7
pre_build_image: true
provisioner:
name: ansible
verifier:
name: ansible
But now when I run molecule test
I get this error:
TASK [red.fake_role : fake_role | Create /tmp/fake] ******************
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-
1668098032.9524324-2225817-158864423468362 `\" && echo ansible-tmp-
1668098032.9524324-2225817-158864423468362=\"` echo
~/.ansible/tmp/ansible-tmp-1668098032.9524324-2225817-158864423468362
`\" ), exited with result 1", "unreachable": true}