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

Cannot use "inventory.links.group_vars" together "inventory.host_vars" #2759

Closed
y-hashida opened this issue Jul 22, 2020 · 6 comments · May be fixed by #4026
Closed

Cannot use "inventory.links.group_vars" together "inventory.host_vars" #2759

y-hashida opened this issue Jul 22, 2020 · 6 comments · May be fixed by #4026

Comments

@y-hashida
Copy link

y-hashida commented Jul 22, 2020

Issue type

  • Feature request
  • Question

molecule and ansible version

$ molecule --version
molecule 3.0.6
   ansible==2.9.11 python==3.8

$ ansible --version
ansible 2.9.11

Desired Behavior

I would like to configure the following settings in "provisioner.inventory" of "molecule.yml".

provisioner:
  ... snip ...
  inventory:
    host_vars:
      ${MOLECULE_DISTRO}-${ANSIBLE_VER}-1:
        ipv4_address: "192.168.1.11"
      ${MOLECULE_DISTRO}-${ANSIBLE_VER}-2:
        ipv4_address: "192.168.1.12"
    links:
      group_vars: ${GROUP_VARS}
  ... snip ...

As you can see from this snippet, here is a summary of what I want to set up.

  • Specify the link indicated by ${GROUP_VARS} in group_vars
  • Include host_vars in molecule.yml.

Actual Behaviour

However, in practice, only the setting of group_vars:${GROUP_VARS} in inventory.links applies. inventory.host_vars will be ignored.

Conversely, if you remove inventory.links, host_vars is not ignored.

provisioner:
  ... snip ...
  inventory:
    host_vars:
      ${MOLECULE_DISTRO}-${ANSIBLE_VER}-1:
        ipv4_address: "192.168.1.11"
      ${MOLECULE_DISTRO}-${ANSIBLE_VER}-2:
        ipv4_address: "192.168.1.12"
    #links:
    #   group_vars: ${GROUP_VARS}
  ... snip ...

In referring to the molecule source code, it seems that the conditional branching is based only on the presence or absence of inventory.links.

https://github.com/ansible-community/molecule/blob/17c5da0e831a36f226769029d6452d8d0d692fd7/molecule/provisioner/ansible.py#L767-L778

If we can't use inventory.links.group_vars and inventory.group_vars together, then that's understandable, but if you can't use inventory.links.group_vars and inventory.host_vars together, then very inconvenient.

I would therefore like to request the following features.

  • The feature to use inventory.links.group_vars and inventory.host_vars together.
  • The feature to use inventory.links.host_vars and inventory.group_vars together.

Alternatively, I would like to know if there is a way to make this work as you wish without modifying the source code.

Best regards.

My molecule.yml and converge.yml

molecule.yml

---
dependency:
  name: galaxy

driver:
  name: lxd

lint: |
  set -e
  ansible-lint ${ROLE_DIR}

platforms:
  - name: ${MOLECULE_DISTRO}-${ANSIBLE_VER}-1
    source:
      alias: ubuntu/${MOLECULE_DISTRO}/amd64

  - name: ${MOLECULE_DISTRO}-${ANSIBLE_VER}-2
    source:
      alias: ubuntu/${MOLECULE_DISTRO}/amd64

provisioner:
  name: ansible
  playbooks:
    create: ${CREATE_YML}
    destroy: ${DESTROY_YML}
    converge: ./playbooks/converge.yml
  optoins:
    diff: true
  inventory:
    host_vars:
      ${MOLECULE_DISTRO}-${ANSIBLE_VER}-1:
        ipv4_address: "192.168.1.11"
      ${MOLECULE_DISTRO}-${ANSIBLE_VER}-2:
        ipv4_address: "192.168.1.12"
    links:
      group_vars: ${GROUP_VARS}

verifier:
  name: testinfra
  directory: ${TESTINFRA_DIR}
  options:
    s: true
    v: true

converge.yml

---
- name: Converge
  hosts: all
  become: yes
  tasks:
    - name: debug
      debug:
        msg: "{{ ipv4_address }}"
@thehybridtechnician
Copy link

Thank you @y-hashida for opening this ticket up. I was just getting ready to do the same thing. :)

@y-hashida
Copy link
Author

@thehybridtechnician
Thank you for your replying!
I'm very much looking forward to that fix!

@fourstepper
Copy link
Contributor

@y-hashida hi, could you please close the issue if it's done? Thanks!

@patademahesh
Copy link

Is this fix merged ? We are still facing the same issue.

$ molecule --version
molecule 3.2.1 using python 3.8 
    ansible:2.10.3
    delegated:3.2.1 from molecule
    docker:0.2.4 from molecule_docker
    vagrant:0.6.1 from molecule_vagrant

@zhan9san
Copy link
Contributor

Do we still need this feature?
If yes, I'd like to look into it.

@y-hashida
Copy link
Author

@zhan9san
Thanks for the reply!
I don't need it anymore because I solved it in another way and I don't use it anymore.

@zhan9san zhan9san closed this as not planned Won't fix, can't repro, duplicate, stale Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants