Molecule test by default runs cleanup before destroy on test
See original GitHub issueIssue Type
- Bug report
Molecule and Ansible details
ansible 2.8.1
config file = None
configured module search path = ['/Users/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/user/Envs/project/lib/python3.7/site-packages/ansible
executable location = /Users/user/Envs/project/bin/ansible
python version = 3.7.3 (default, Jun 25 2019, 11:10:25) [Clang 10.0.1 (clang-1001.0.46.4)]
molecule, version 2.20.1
Molecule installation method (one of):
- pip
Ansible installation method (one of):
- pip
Detail any linters or test runners used:
Desired Behavior
Molecule test runs like the following:
test_sequence:
- lint
- destroy
- dependency
- syntax
- create
- prepare
- converge
- idempotence
- side_effect
- verify
- cleanup
- destroy
Actual Behaviour
Molecule test is being ran like the following:
test_sequence:
- lint
- cleanup
- destroy
- dependency
- syntax
- create
- prepare
- converge
- idempotence
- side_effect
- verify
- cleanup
- destroy
Molecule test should not run cleanup before VMs are created and converged. Molecule test fails because ansible canβt run on vms that do not exist yet. This is using Vagrant/Virtualbox, I have not tested with Docker.
Molecule Test Log
--> Validating schema /Users/user/git/project/roles/common/molecule/default/molecule.yml.
Validation completed successfully.
--> Test matrix
βββ default
βββ lint
βββ cleanup
βββ destroy
βββ dependency
βββ syntax
βββ create
βββ prepare
βββ converge
βββ idempotence
βββ side_effect
βββ verify
βββ cleanup
βββ destroy
--> Inventory /Users/user/git/project/roles/common/molecule/default/../../../../development.yml linked to /var/folders/pl/rxj8k5v54017g9nnb34yxkr4tg3p52/T/molecule/common/default/inventory/hosts
--> Inventory /Users/user/git/project/roles/common/molecule/default/../../../../group_vars/ linked to /var/folders/pl/rxj8k5v54017g9nnb34yxkr4tg3p52/T/molecule/common/default/inventory/group_vars
--> Inventory /Users/user/git/project/roles/common/molecule/default/../../../../host_vars/ linked to /var/folders/pl/rxj8k5v54017g9nnb34yxkr4tg3p52/T/molecule/common/default/inventory/host_vars
--> Scenario: 'default'
--> Action: 'lint'
--> Executing Yamllint on files found in /Users/user/git/project/roles/common/...
Lint completed successfully.
--> Executing Flake8 on files found in /Users/user/git/project/roles/common/molecule/default/tests/...
Lint completed successfully.
--> Executing Ansible Lint on /Users/user/git/project/roles/common/molecule/default/playbook.yml...
Lint completed successfully.
--> Inventory /Users/user/git/project/roles/common/molecule/default/../../../../development.yml linked to /var/folders/pl/rxj8k5v54017g9nnb34yxkr4tg3p52/T/molecule/common/default/inventory/hosts
--> Inventory /Users/user/git/project/roles/common/molecule/default/../../../../group_vars/ linked to /var/folders/pl/rxj8k5v54017g9nnb34yxkr4tg3p52/T/molecule/common/default/inventory/group_vars
--> Inventory /Users/user/git/project/roles/common/molecule/default/../../../../host_vars/ linked to /var/folders/pl/rxj8k5v54017g9nnb34yxkr4tg3p52/T/molecule/common/default/inventory/host_vars
--> Scenario: 'default'
--> Action: 'cleanup'
PLAY [Converge] ****************************************************************
TASK [Gathering Facts] *********************************************************
fatal: [cos-7]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname cos-7: nodename nor servname provided, or not known", "unreachable": true}
fatal: [u-1604]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host u-1604 port 22: Operation timed out", "unreachable": true}
fatal: [u-1804]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host u-1804 port 22: Operation timed out", "unreachable": true}
PLAY RECAP *********************************************************************
cos-7 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
u-1604 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
u-1804 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
ERROR:
An error occurred during the test sequence action: 'cleanup'. Cleaning up.
--> Inventory /Users/user/git/project/roles/common/molecule/default/../../../../development.yml linked to /var/folders/pl/rxj8k5v54017g9nnb34yxkr4tg3p52/T/molecule/common/default/inventory/hosts
--> Inventory /Users/user/git/project/roles/common/molecule/default/../../../../group_vars/ linked to /var/folders/pl/rxj8k5v54017g9nnb34yxkr4tg3p52/T/molecule/common/default/inventory/group_vars
--> Inventory /Users/user/git/project/roles/common/molecule/default/../../../../host_vars/ linked to /var/folders/pl/rxj8k5v54017g9nnb34yxkr4tg3p52/T/molecule/common/default/inventory/host_vars
--> Scenario: 'default'
--> Action: 'destroy'
PLAY [Destroy] *****************************************************************
TASK [Destroy molecule instance(s)] ********************************************
ok: [localhost] => (item=None)
ok: [localhost] => (item=None)
ok: [localhost] => (item=None)
ok: [localhost]
TASK [Populate instance config] ************************************************
ok: [localhost]
TASK [Dump instance config] ****************************************************
skipping: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Molecule test by default runs cleanup before destroy on test
The cleanup step is executed directly before every destroy step. Just like the destroy step, it will be run twice. An initial clean...
Read more >Command Line Reference β Molecule Documentation
This action has cleanup and is not enabled by default. ... class molecule.command.destroy.Destroy ... This action is run only once per...
Read more >Testing your Ansible roles with Molecule - Jeff Geerling
just a quick note to add to your article. One very nice feature of Molecule when testing with Docker is the `--destroy-never` flag...
Read more >Developing and Testing Ansible Roles with Molecule and ...
By default, βmolecule testβ executes these steps in order: Install required dependencies; Lint the project; Destroy existing instances; Run aΒ ...
Read more >1867413 β molecule ignores the driver-name option
molecule test Actual results: $ molecule test --> Test matrix βββ default βββ dependency βββ lint βββ cleanup βββ destroy ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I end up with something like this:
Sadly I have to sacrifice 10 seconds to know whether instances has been spawned yet or not.
Iβm presently using
when: ansible_host != inventory_hostname
on tasks in cleanup.yml and that seems to working asansible_host
is populated in the inventory file when the host is created.