No. You are mixing up groups and hosts (and probably the inventory as well).
All variables under group_vars are meant to be specific to groups only
- not hosts.
Hosts specific variables go under their respective host_vars files.
Host and group specific variables can be set in the inventory,
group_vars, and host_vars.
Setting stuff in the inventory is usually done for very simple structures.
Given that your host specific data is already a nested dictionary, I
would not use the inventory for that.
Your example indicates that the entire 'interfaces' dictionary is, in
fact, not variable, it's the same for each host. You can add this to
the group_vars in this case:
interfaces:
mgmt_interface:
name: em0
ip: "{{ ansible_hostname }}"
If your data is in fact different, please post a more accurate example.
On Tue, 28 Apr 2020 at 20:32, Momodou Fatty <[email protected]> wrote:
>
> @Dick ... In fact, I have group_vars/all.yaml and in there I have stuff like
> credentials and username/password, since this is common for all devices
> I can create group_vars/eos_group.yaml and group_vars/junos_group.yaml.
> However, this still does not solve the issue of having multiple variables for
> the multiple hosts in the same file.
>
> Okay let's say I now have group_vars/junos_group.yaml. Inside this file I
> have the defined variables for 10 different hosts.
> 10.10.10.10:
> hostname: hostname1
> data_nexthop: 10.10.10.1
> interfaces:
> mgmt_interface:
> name: em0
> ip: 10.10.10.10:
> 12.12.12.12:
> hostname: hostname2
> data_nexthop: 12.12.12.1
> interfaces:
> mgmt_interface:
> name: em0
> ip: 12.12.12.12
>
> In my playbook, I can reference value em0 with "{{
> group_vars[inventory_hostname]['interfaces']['mgmt_interface']['name'] }}"
>
> Is this correct?
> Thanks
>
> On Tuesday, April 28, 2020 at 10:26:39 AM UTC-7, Dick Visser wrote:
>>
>> First off, rename your groups to NOT have a hyphen. This is critical.
>> Then, use group_var/junos_group/ and define the common stuff below there.
>> Same for the group_vars/eos_group/
>>
>> it's all laid out in
>> https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html
>>
>> Dick
>>
>>
>> On Tue, 28 Apr 2020 at 19:16, Momodou Fatty <[email protected]> wrote:
>> >
>> > Let's say I have two groups of devices to configure, eos-group and
>> > junos-group.
>> >
>> > Let's focus on junos-group.
>> > I have 10 devices in the junos-group.
>> > Each device will be configured with a mgmt ip, hostname, interface, routes
>> > ...etc
>> >
>> > Inside of /etc/ansible/host_vars/, I could create different files for
>> > each host: hostname1.yaml, hostname2.yaml ....
>> > However, this doesn't. scale, does it?
>> >
>> > Can I just create one file (lets call it all_junos_hosts.yaml) inside
>> > /etc/ansible/host_vars/, and inside of t his single file, I'll use
>> > hierarchical structure to define variables for different hosts?
>> > E.g: my all_junos_hosts.yaml file will look like this:
>> >
>> > 10.10.10.10:
>> > hostname: hostname1
>> > data_nexthop: 10.10.10.1
>> > interfaces:
>> > mgmt_interface:
>> > name: em0
>> > ip: 10.10.10.10:
>> > 12.12.12.12:
>> > hostname: hostname2
>> > data_nexthop: 12.12.12.1
>> > interfaces:
>> > mgmt_interface:
>> > name: em0
>> > ip: 12.12.12.12
>> >
>> > I read somewhere that if I create a file called all_junos_hosts.yaml
>> > inside of /etc/ansible/host_vars/, ansible will think there is a host
>> > called all_junos_hosts.yaml.
>> > How do I get around this?
>> >
>> > Basically all I want to do is, in my template, I'll do something like set
>> > interfaces management "{{ reference for mgmt interface for this host }}"
>> > ... etc
>> >
>> > --
>> > You received this message because you are subscribed to the Google Groups
>> > "Ansible Project" group.
>> > To unsubscribe from this group and stop receiving emails from it, send an
>> > email to [email protected].
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msgid/ansible-project/853a412c-2b95-4e99-94bf-3da30badb559%40googlegroups.com.
>>
>>
>>
>> --
>> Dick Visser
>> Trust & Identity Service Operations Manager
>> GÉANT
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/2b131d1e-c292-4cb4-a71e-8d03578d9b77%40googlegroups.com.
--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAL8fbwOALbu_%2BetVcJTriFKpON%3DV9x7yKMX2PVaTwae0Rtem-A%40mail.gmail.com.