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.

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

See original GitHub issue

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 }}"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
thehybridtechniciancommented, Jul 22, 2020

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

1reaction
zhan9sancommented, Jun 15, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to build your inventory - Ansible Documentation
Ansible automates tasks on managed nodes or “hosts” in your infrastructure, using a list or group of lists known as inventory. You can...
Read more >
Ansible - get variables from group_vars and host_vars ...
So I would like to get the hostvars from groups kafka and zookeeper. Here are hostvars and groups, defined in the main inventory...
Read more >
Accessing hostvars for a host group in Ansible - Server Fault
I have a group of servers that I need to talk to each other over a private LAN. My inventory file: [server_list] server1...
Read more >
List ALL Ansible variables for a host or group with an ad hoc ...
With dynamic inventory script hosts.sh : ... Use the existing answer for hostvars: ... To also debug Task behaviour use register:.
Read more >
How to use different Ansible variables with examples
playbook group_vars /*; inventory file or script host vars; inventory host_vars /*; playbook host_vars /*; host facts / cached set_facts; play vars; play ......
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