question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Molecule test by default runs cleanup before destroy on test

See original GitHub issue

Issue 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:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
Zempashicommented, Jul 14, 2019

I end up with something like this:

---
- hosts: all
  gather_facts: false
  tasks:
    - wait_for_connection:
        timeout: 10
      register: wait_for_instances
      failed_when: false

    - name: 'cleanup'
      command: losetup -d /dev/loop0
      when: wait_for_instances.elapsed < 10

Sadly I have to sacrifice 10 seconds to know whether instances has been spawned yet or not.

2reactions
jghalcommented, Sep 11, 2019

I’m presently using when: ansible_host != inventory_hostname on tasks in cleanup.yml and that seems to working as ansible_host is populated in the inventory file when the host is created.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found