Skip to content

molecule does not read variables from role #4345

Open
@MaKaNu

Description

@MaKaNu

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 24.12.0 using python 3.11 
    ansible:2.18.0
    azure:23.5.3 from molecule_plugins
    default:24.12.0 from molecule
    openstack:23.5.3 from molecule_plugins requiring collections: openstack.cloud>=2.1.0
    vagrant:23.5.3 from molecule_plugins
    containers:23.5.3 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
    ec2:23.5.3 from molecule_plugins
    gce:23.5.3 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
    docker:23.5.3 from molecule_plugins requiring collections: community.docker>=3.4.11 ansible.posix>=1.4.0
    podman:23.5.3 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0

What happened

running molecule converge I get the following:

TASK [Include vars] ************************************************************
ok: [ubuntu2404]

TASK [Include defaults] ********************************************************
ok: [ubuntu2404]

TASK [debug] *******************************************************************
ok: [ubuntu2404] => {
    "fixed_apache_package": "VARIABLE IS NOT DEFINED!"
}

TASK [debug] *******************************************************************
ok: [ubuntu2404] => {
    "apache_package": "VARIABLE IS NOT DEFINED!"
}

Instead I expected to see the values of the vars.

Reproducing example

converge.yml

---
- name: Converge
  hosts: all
  tasks:
    - name: Include vars
      ansible.builtin.include_vars:
        dir: '{{ lookup("env", "MOLECULE_PROJECT_DIRECTORY") }}/vars/'
        extensions:
          - 'yml'

    - name: Include defaults
      ansible.builtin.include_vars:
        dir: '{{ lookup("env", "MOLECULE_PROJECT_DIRECTORY") }}/defaults/'
        extensions:
          - 'yml'

    - debug:
        var: fixed_apache_package

    - debug:
        var: apache_package

defaults

---
# defaults file for apache
apache_package: "{{ fixed_apache_package }}"
apache_service: "{{ fixed_apache_service }}"
prepare_certbot: true

vars

---
# vars file for apache

fixed_apache_package_variants:
  default: apache2
  ubuntu_20: apache2
  ubuntu_22: apache2
  ubuntu_24: apache2

fixed_apache_package: >-
  {{
    __apache_package_variants[__distro_version] |
      default(__apache_package_variants[__os_version]) |
      default(__apache_package_variants["default"])
  }}

fixed_apache_service_variants:
  default: apache2
  ubuntu_20: apache2
  ubuntu_22: apache2
  ubuntu_24: apache2

fixed_apache_service: >-
  {{
    __apache_service_variants[__distro_version] |
      default(__apache_service_variants[__os_version]) |
      default(__apache_service_variants["default"])
  }}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions