I hit this problem every once in a while; basically, I run molecule test
or molecule converge
(in this case it was for a Kubernetes Operator I was building with Ansible), and it says the instance is already created/prepared—even though it is not—and then Molecule fails on the 'Gathering Facts' portion of the converge step:
--> Scenario: 'test-local'
--> Action: 'dependency'
Skipping, missing the requirements file.
--> Scenario: 'test-local'
--> Action: 'create'
Skipping, instances already created.
--> Scenario: 'test-local'
--> Action: 'prepare'
Skipping, instances already prepared.
--> Scenario: 'test-local'
--> Action: 'converge'
PLAY [Build Operator in Kubernetes docker container] ***************************
TASK [Gathering Facts] *********************************************************
fatal: [kind-test-local]: UNREACHABLE! => {"changed": false, "msg": "Authentication or permission failure. 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". Failed command was: ( umask 77 && mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1570656925.36-200640620205465 `" && echo ansible-tmp-1570656925.36-200640620205465="` echo ~/.ansible/tmp/ansible-tmp-1570656925.36-200640620205465 `" ), exited with result 1", "unreachable": true}
This usually happens when I cleaned up a Molecule test container or VM myself, without using molecule
to do so. And usually, it's fixed by running:
molecule destroy
But in one case, I used a custom scenario, so I should've used:
molecule destroy -s [scenario-name]
But I forgot to do that, so was puzzling over why deleting the molecule/
directory from /tmp
and $TMPDIR
didn't fix any problems.
Eventually I ran molecule --debug converge
to see all the paths in use, and noticed that some configs are stored in ~/.cache/molecule
.
So I went ahead and deleted the entire ~/.cache/molecule
directory (don't do this unless you know there aren't other active molecule environments that are being used!), and then ran molecule converge -s [scenario-name]
again... and it worked!
In the future, I might remember to just make sure I do molecule destroy
with the scenario... or I'll Google the problem and find this blog post and then do it :)
Comments
Hi there, I recently followed your blogs regarding molecule.
I have a molecule test where I have create.yml, converge.yml, verify.yml, destroy.yml.
My create.yml is starting an AWS EC2 instance (manually created before hand but not started yet), and adding it to host by add_host module.
However, when converge runs it cannot get the added host, with error message below.
"Failed to connect to the host via ssh: ssh: Could not resolve hostname instance: Name or service not known"
I also tried to check ~/.cache/molecule, delete and rerun but it goes with same results.
Do you have an idea why it cannot get the hostname which was added?
Thank you very much for input.
It appears that these days you can issue "molecule reset" and it will effectively clear out that .cache directory. If you do that from within a role it'll only clear out whatever pertains to that role.
I have an other kind of problem, follow you chapter 13 to do a first simple test with molecule I have the follow error:
Just want to test the apache playbook of Chapter 13
Good chance this is related to Molecule's latest code. I found last week that I couldn't run tests if I upgraded Molecule in my existing tests. So I spent Sunday afternoon trying unsuccessfully to get Molecule running using the official Getting Started guide for a completely new scenario. I may be missing something obvious, but Molecule sure looks broken to me at the moment.
Aha so I'm NOT the only one who googles for answers only to find their own post from a year ago!
Heh, I've run into this post a few times since writing it already!