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

molecule does not read variables from role #4345

Open
7 tasks done
MaKaNu opened this issue Dec 19, 2024 · 2 comments
Open
7 tasks done

molecule does not read variables from role #4345

MaKaNu opened this issue Dec 19, 2024 · 2 comments

Comments

@MaKaNu
Copy link

MaKaNu commented Dec 19, 2024

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"])
  }}
@ssbarnea
Copy link
Member

ssbarnea commented Jan 8, 2025

Can you run the same playbook with ansible directory (and pass a valid MOLECULE_PROJECT_DIRECTORY) and get the correct result? If yes, it might count as a bug, otherwise not.

@MaKaNu
Copy link
Author

MaKaNu commented Jan 8, 2025

Can you specify what you mean by ansible directory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants