Cannot use "inventory.links.group_vars" together "inventory.host_vars"
See original GitHub issueIssue 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.
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:
- Created 3 years ago
- Reactions:6
- Comments:6 (2 by maintainers)
Thank you @y-hashida for opening this ticket up. I was just getting ready to do the same thing. 😃
Do we still need this feature? If yes, I’d like to look into it.