Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When including more than 1 entry in platforms molecule_inventory.yml doesn't contain all entries #4058

Closed
7 tasks done
brandor5 opened this issue Sep 27, 2023 · 2 comments · Fixed by #4068
Closed
7 tasks done
Labels

Comments

@brandor5
Copy link
Contributor

Prerequisites

  • This was not already reported in the past (duplicate check)
  • It does reproduce it with code from main branch (latest unreleased version)
  • I include a minimal example for reproducing the bug
  • The bug is not trivial, as for those a direct pull-request is preferred
  • Running pip check does not report any conflicts
  • I was able to reproduce the issue on a different machine
  • The issue is not specific to any driver other than 'default' one

Environment

$ molecule --version
molecule 6.0.2 using python 3.9
ansible:2.15.4
default:6.0.2 from molecule

$ rpm -q python3
python3-3.9.16-1.el9_2.1.x86_64

$ rpm -q ansible-core
ansible-core-2.15.4-1.el9ap.noarch

$ rpm -q molecule
molecule-6.0.2-1.el9ap.noarch

$ cat /etc/redhat-release
Red Hat Enterprise Linux release 9.2 (Plow)

What happened

I followed the Red Hat blog [0] example and then followed the docs [1] to enable podman containers. Everything appeared to work, however when I ran molecule test not all platform entries are destroyed.

$ podman ps -a
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES
[brandor5@dev extensions]$ cat molecule/default/molecule.yml 
---
dependency:
  name: galaxy
  options:
    requirements-file: requirements.yml

platforms:
  - name: ubi8
    image: registry.access.redhat.com/ubi8/ubi-init:latest
  - name: ubi9
    image: registry.access.redhat.com/ubi9/ubi-init:latest

provisioner:
  name: ansible
  config_options:
    defaults:
      collections_path: ${ANSIBLE_COLLECTIONS_PATH}

driver:
  options:
    managed: False
    login_cmd_template: 'podman exec -ti {instance} bash'
    ansible_connection_options:
      ansible_connection: podman
[brandor5@dev extensions]$ molecule test
INFO     default scenario test matrix: dependency, cleanup, destroy, syntax, create, prepare, converge, idempotence, side_effect, verify, cleanup, destroy
INFO     Performing prerun with role_name_check=0...
INFO     Running default > dependency
Starting galaxy collection install process
Nothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.
INFO     Dependency completed successfully.
WARNING  Skipping, missing the requirements file.
INFO     Running default > cleanup
WARNING  Skipping, cleanup playbook not configured.
INFO     Running default > destroy
[WARNING]: Could not match supplied host pattern, ignoring: molecule

PLAY [Destroy molecule containers] *********************************************
skipping: no hosts matched

PLAY [Remove dynamic molecule inventory] ***************************************

TASK [Remove dynamic inventory file] *******************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

INFO     Running default > syntax
[WARNING]: Could not match supplied host pattern, ignoring: molecule

playbook: /home/brandor5/work/ansible-collections/ansible_collections/foo/bar/extensions/molecule/default/converge.yml
INFO     Running default > create

PLAY [Create] ******************************************************************

TASK [Create a container] ******************************************************
changed: [localhost] => (item={'image': 'registry.access.redhat.com/ubi8/ubi-init:latest', 'name': 'ubi8'})
changed: [localhost] => (item={'image': 'registry.access.redhat.com/ubi9/ubi-init:latest', 'name': 'ubi9'})

TASK [Fail if container is not running] ****************************************
skipping: [localhost] => (item=ubi8) 
skipping: [localhost] => (item=ubi9) 
skipping: [localhost]

TASK [Add container to molecule_inventory] *************************************
ok: [localhost] => (item=ubi8)
ok: [localhost] => (item=ubi9)

TASK [Dump molecule_inventory] *************************************************
changed: [localhost]

TASK [Force inventory refresh] *************************************************

TASK [Fail if molecule group is missing] ***************************************
ok: [localhost] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY [Validate that inventory was refreshed] ***********************************

TASK [Check uname] *************************************************************
ok: [ubi9]

TASK [Display uname info] ******************************************************
ok: [ubi9] => {
    "msg": "Linux c2c968db5538 5.14.0-284.30.1.el9_2.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Aug 25 09:13:12 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux\n"
}

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=2    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0
ubi9                       : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

INFO     Running default > prepare
WARNING  Skipping, prepare playbook not configured.
INFO     Running default > converge

PLAY [Fail if molecule group is missing] ***************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [Print some info] *********************************************************
ok: [localhost] => {
    "msg": {
        "all": [
            "ubi8",
            "ubi9"
        ],
        "molecule": [
            "ubi9"
        ],
        "ungrouped": [
            "ubi8"
        ]
    }
}

TASK [Assert group existence] **************************************************
ok: [localhost] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY [Converge] ****************************************************************

TASK [Check uname] *************************************************************
ok: [ubi9]

TASK [Print some info] *********************************************************
ok: [ubi9] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ubi9                       : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

INFO     Running default > idempotence

PLAY [Fail if molecule group is missing] ***************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [Print some info] *********************************************************
ok: [localhost] => {
    "msg": {
        "all": [
            "ubi8",
            "ubi9"
        ],
        "molecule": [
            "ubi9"
        ],
        "ungrouped": [
            "ubi8"
        ]
    }
}

TASK [Assert group existence] **************************************************
ok: [localhost] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY [Converge] ****************************************************************

TASK [Check uname] *************************************************************
ok: [ubi9]

TASK [Print some info] *********************************************************
ok: [ubi9] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ubi9                       : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

INFO     Idempotence completed successfully.
INFO     Running default > side_effect
WARNING  Skipping, side effect playbook not configured.
INFO     Running default > verify
INFO     Running Ansible Verifier
WARNING  Skipping, verify action has no playbook.
INFO     Verifier completed successfully.
INFO     Running default > cleanup
WARNING  Skipping, cleanup playbook not configured.
INFO     Running default > destroy

PLAY [Destroy molecule containers] *********************************************

TASK [Stop and remove container] ***********************************************
changed: [ubi9 -> localhost]

TASK [Remove potentially stopped container] ************************************
ok: [ubi9 -> localhost]

PLAY [Remove dynamic molecule inventory] ***************************************

TASK [Remove dynamic inventory file] *******************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ubi9                       : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

INFO     Pruning extra files from scenario ephemeral directory
[brandor5@dev extensions]$ podman ps -a
CONTAINER ID  IMAGE                                            COMMAND     CREATED         STATUS         PORTS       NAMES
4a62ce804639  registry.access.redhat.com/ubi8/ubi-init:latest  sleep 1d    34 seconds ago  Up 34 seconds              ubi8

[0] https://developers.redhat.com/articles/2023/09/13/introducing-ansible-molecule-ansible-automation-platform
[1] https://ansible.readthedocs.io/projects/molecule/podman/

Reproducing example

---
dependency:
  name: galaxy
  options:
    requirements-file: requirements.yml

platforms:
  - name: ubi8
    image: registry.access.redhat.com/ubi8/ubi-init:latest
  - name: ubi9
    image: registry.access.redhat.com/ubi9/ubi-init:latest

provisioner:
  name: ansible
  config_options:
    defaults:
      collections_path: ${ANSIBLE_COLLECTIONS_PATH}

driver:
  options:
    managed: False
    login_cmd_template: 'podman exec -ti {instance} bash'
    ansible_connection_options:
      ansible_connection: podman
@brandor5
Copy link
Contributor Author

Sorry, should have included this:

$ molecule create
INFO     default scenario test matrix: dependency, create, prepare
INFO     Performing prerun with role_name_check=0...
INFO     Running default > dependency
Starting galaxy collection install process
Nothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.
INFO     Dependency completed successfully.
WARNING  Skipping, missing the requirements file.
INFO     Running default > create

PLAY [Create] ******************************************************************

TASK [Create a container] ******************************************************
changed: [localhost] => (item={'image': 'registry.access.redhat.com/ubi8/ubi-init:latest', 'name': 'ubi8'})
changed: [localhost] => (item={'image': 'registry.access.redhat.com/ubi9/ubi-init:latest', 'name': 'ubi9'})

TASK [Fail if container is not running] ****************************************
skipping: [localhost] => (item=ubi8) 
skipping: [localhost] => (item=ubi9) 
skipping: [localhost]

TASK [Add container to molecule_inventory] *************************************
ok: [localhost] => (item=ubi8)
ok: [localhost] => (item=ubi9)

TASK [Dump molecule_inventory] *************************************************
changed: [localhost]

TASK [Force inventory refresh] *************************************************

TASK [Fail if molecule group is missing] ***************************************
ok: [localhost] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY [Validate that inventory was refreshed] ***********************************

TASK [Check uname] *************************************************************
ok: [ubi9]

TASK [Display uname info] ******************************************************
ok: [ubi9] => {
    "msg": "Linux 581abc58dcf3 5.14.0-284.30.1.el9_2.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Aug 25 09:13:12 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux\n"
}

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=2    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0
ubi9                       : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

INFO     Running default > prepare
WARNING  Skipping, prepare playbook not configured.

[brandor5@dev extensions]$ cat ~/.cache/molecule/extensions/default/inventory/molecule_inventory.yml 
all:
  children:
    molecule:
      hosts:
        ubi9: {ansible_connection: containers.podman.podman}

@ssbarnea ssbarnea added bug and removed new labels Oct 4, 2023
@clickthisnick
Copy link
Contributor

I just ran into the same thing - {{ molecule_inventory | combine(inventory_partial_yaml | from_yaml, recursive=true) }} will fix that

ssbarnea pushed a commit that referenced this issue Oct 17, 2023
Previous behavior is your molecule group would only contain the last
platform since the elements were not merging:

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/combine_filter.html


```
TASK [Display uname info] ******************************************************
ok: [foo] => {
    "msg": "Linux...\n"
}
```

New behavior is all of your platforms will be in the host inventory

```
TASK [Display uname info] ******************************************************
ok: [foo] => {
    "msg": "Linux...\n"
}
ok: [bar] => {
    "msg": "Linux...\n"
}
```

Fixes: #4058
@github-project-automation github-project-automation bot moved this from Roadmap to Done in 🧰 devtools project board Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants