# Create a variable of interfaces from an IOS switch based on the way they are configured.

**URL:** <https://forum.ansible.com/t/create-a-variable-of-interfaces-from-an-ios-switch-based-on-the-way-they-are-configured/34099>\
**Category:** Ansible Project\
**Created:** [October 24, 2020, 3:46pm UTC](https://forum.ansible.com/t/create-a-variable-of-interfaces-from-an-ios-switch-based-on-the-way-they-are-configured/34099 "2020-10-24T15:46:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Lucht](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@Richard\_Lucht](https://forum.ansible.com/u/Richard_Lucht)\
**Post date:** [October 24, 2020, 3:46pm UTC](https://forum.ansible.com/t/create-a-variable-of-interfaces-from-an-ios-switch-based-on-the-way-they-are-configured/34099/1 "2020-10-24T15:46:27Z")

</div>

Hello, I am looking for way to pull interfaces from an cisco switch and make them a variable based on they way they are currently configured so I can make configuration changes. For example if it is a trunk interface make those the variable or list so I can add another allowed vlan. Or if it is an access port and this access vlan select those ports so I can make changes.

I can pull a list of interfaces from a switch using

- name: show interfaces

hosts: all

connection: network\_cli

gather\_facts: no

vars:

ansible\_network\_os: ios

tasks:

- name: test

ios\_facts:

gather\_subset:

- ‘min’

gather\_network\_resources:

- l2\_interfaces

And get this result

{

“ansible\_facts”: {

“ansible\_network\_resources”: {

“l2\_interfaces”: [

{

“name”: “GigabitEthernet0/0”

},

{

“name”: “GigabitEthernet1/0/1”,

“access”: {

“vlan”: 3456

}

},

{

“name”: “GigabitEthernet1/0/2”,

“access”: {

“vlan”: 3456

}

},

{

“name”: “GigabitEthernet1/0/3”,

“access”: {

“vlan”: 3456

}

},

{

“name”: “GigabitEthernet1/0/4”,

“access”: {

“vlan”: 3456

{

“name”: “GigabitEthernet1/0/20”,

“trunk”: {

“allowed\_vlans”: [

“32”,

“1978”,

“1980”,

“3456”

]

}

},

But I am having issues find a way to select and use the interfaces that are either a trunk or access and what access vlan to select.

Any help with this would be greatly appreciated.

Thank you
