# Need to get the network interface status.

**URL:** <https://forum.ansible.com/t/need-to-get-the-network-interface-status/23094>\
**Category:** Ansible Project\
**Created:** [November 24, 2016, 2:03pm UTC](https://forum.ansible.com/t/need-to-get-the-network-interface-status/23094 "2016-11-24T14:03:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lishyalak](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@lishyalak](https://forum.ansible.com/u/lishyalak)\
**Post date:** [November 24, 2016, 2:03pm UTC](https://forum.ansible.com/t/need-to-get-the-network-interface-status/23094/1 "2016-11-24T14:03:02Z")

</div>

Number of network interfaces varies in our environment and we have atleast 5 variants, hardcoding is not an option.  
This playbook need to check {{ ansible\_interfaces }} and then get the status of all available interfaces active status.  
from the example snippet below

“ansible\_eth1”: {  
“active”: true,  
“device”: “eth1”,

I am trying to set\_fact which should return the dict like  
“eth1status\_active” = “yes”  
eth0status\_active" = “no”

…  
ethxstatus\_active = ‘xxx’

I have lost just before the last task

tasks:

- name: get filesystem  
setup: gather\_subset=network

- name: set fact network\_interfaces  
set\_fact: network\_interfaces={{ ansible\_interfaces }}

- name: set fact  
set\_fact: iface\_item=“ansible\_{{ item }}”  
with\_items: “{{ ansible\_interfaces }}”  
register: iface\_result

- name: make a list  
set\_fact: iface\_list=“{{ iface\_result.results | map(attribute=‘ansible\_facts.iface\_item’) | list }}”

Please help me continue playing …

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 29, 2016, 3:29pm UTC](https://forum.ansible.com/t/need-to-get-the-network-interface-status/23094/2 "2016-11-29T15:29:44Z")

</div>

You only need one task like this:

- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"{{ item | replace('-', '\_') }}status\_active": "{{ hostvars[inventory\_hostname]['ansible\_' + item | replace('-', '\_')].active }}"  
&nbsp;&nbsp;&nbsp;with\_items: "{{ ansible\_interfaces }}"

The replace is needed since dash in variable names is not allowed.
