# Ansible variables with network switches

**URL:** <https://forum.ansible.com/t/ansible-variables-with-network-switches/38099>\
**Category:** Ansible Project\
**Created:** [June 13, 2023, 6:36pm UTC](https://forum.ansible.com/t/ansible-variables-with-network-switches/38099 "2023-06-13T18:36:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cristian\_Cardoso](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@Cristian\_Cardoso](https://forum.ansible.com/u/Cristian_Cardoso)\
**Post date:** [June 13, 2023, 6:36pm UTC](https://forum.ansible.com/t/ansible-variables-with-network-switches/38099/1 "2023-06-13T18:36:26Z")

</div>

I’m using ansible to configure ports on my Juniper switches where I use LACP to configure an aggregation of ports from a server on two different switches, where eth0 will be connected to switch 01 and eth1 to switch 02

I created a template for configuring the interfaces, which follows below:

_interfaces {_  
_xe-0/0/{{ id\_interface }} {_  
_description “{{ interface\_descricao }}”;_  
_ether-options {_  
_802.3ad ae{{ id\_ae\_interface }};_  
_}_  
_}_  
_}_

Inside the main.yml file that is in the vars directory, I insert the variables to populate the fields

_interface\_id: 30_  
_id\_ae\_interface: 23_  
_interface\_description: eth0-VMHOST422_

Here comes my question/problem, as I mentioned before, I need to configure the eth0 port and the eth1 port, where the eth0 port goes on switch 01 and the eth1 port on switch 02, is there any way to make it possible to populate the variables with eth0 and eth1 port in just one run?

Or if anyone has experienced this and solved it in some other way, I would be grateful for the help.

---

<div class="post-metadata">

**Author:** ![Andrew\_Latham](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Latham](https://forum.ansible.com/u/Andrew_Latham)\
**Post date:** [June 13, 2023, 9:04pm UTC](https://forum.ansible.com/t/ansible-variables-with-network-switches/38099/2 "2023-06-13T21:04:06Z")

</div>

Away from my lab but knee-jerk is that group-vars should allow you to organize that information.

---

<div class="post-metadata">

**Author:** ![Cristian\_Cardoso](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@Cristian\_Cardoso](https://forum.ansible.com/u/Cristian_Cardoso)\
**Post date:** [June 15, 2023, 1:32pm UTC](https://forum.ansible.com/t/ansible-variables-with-network-switches/38099/3 "2023-06-15T13:32:09Z")

</div>

Hi Andrew

Thanks for the tip, it was spot on.

I created the group\_vars directory and the qfx.yml file that looks like this:

_qfx:_  
_qfx01:_  
_- {‘name’: ‘xe-0/0/40’, ‘description’: ‘eth0-VMHOST-TESTE’}_  
_- {‘ae’: ‘ae45’, ‘members’: ‘xe-0/0/40’}_

_qfx2:_  
_- {‘name’: ‘xe-0/0/40’, ‘description’: ‘eth1-VMHOST-TESTE’}_

And my tasks were like this, executing the generated loop and with a conditional in the execution

_- name: Configurando interfaces nos switches_  
_junipernetworks.junos.junos\_interfaces:_  
_config:_  
_- name: “{{ item.name }}”_  
_description: “{{ item.description }}”_  
_loop: “{{ qfx[inventory\_hostname] }}”_  
_when: item.name is defined_  
_tags:_  
_- loop-interface_

_- name: Configurando interfaces ae’s nas interfaces dos switches_  
_junipernetworks.junos.junos\_lag\_interfaces:_  
_config:_  
_- name: “{{ item.ae }}”_  
_members:_  
_- member: “{{ item.members }}”_  
_loop: “{{ qfx[inventory\_hostname] }}”_  
_when: item.ae is defined_  
_tags:_  
_- loop-ae_

Again, thank you very much.
