# loop on ios fact error

**URL:** <https://forum.ansible.com/t/loop-on-ios-fact-error/34779>\
**Category:** Ansible Project\
**Created:** [March 14, 2021, 12:11am UTC](https://forum.ansible.com/t/loop-on-ios-fact-error/34779 "2021-03-14T00:11:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Three\_PaX](https://avatars.discourse-cdn.com/v4/letter/t/9dc877/32.png) [@Three\_PaX](https://forum.ansible.com/u/Three_PaX)\
**Post date:** [March 14, 2021, 12:11am UTC](https://forum.ansible.com/t/loop-on-ios-fact-error/34779/1 "2021-03-14T00:11:16Z")

</div>

hello guyz here my playbook

- name: Play on switch  
hosts: Paris  
gather\_facts: no

tasks:

- name: set fact  
ios\_facts:  
gather\_subset: all  
register: ansible\_net\_interfaces

- debug:  
var: ansible\_net\_interfaces

- name: Ajouter ligne COS\_in  
ios\_config:  
lines:

- service-policy input COS-IN  
parents: interface {{ item.key }}  
with\_dict: “{{ ansible\_net\_interfaces }}”  
when: item.value.operstatus == “up”

and i got this error

TASK [Ajouter ligne COS\_in] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [Paris]: FAILED! =\> {“msg”: “The conditional check ‘item.value.operstatus == "up"’ failed. The error was: error while evaluating conditional (item.value.operstatus == "up"): ‘bool object’ has no attribute ‘operstatus’\n\nThe error appears to be in ‘/etc/ansible/playbooks/erase.yaml’: line 13, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Ajouter ligne COS\_in\n ^ here\n”}

did somebody can help ?

regards

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 14, 2021, 4:52am UTC](https://forum.ansible.com/t/loop-on-ios-fact-error/34779/2 "2021-03-14T04:52:22Z")

</div>

Where is the output of the debug task?

---

<div class="post-metadata">

**Author:** ![Three\_PaX](https://avatars.discourse-cdn.com/v4/letter/t/9dc877/32.png) [@Three\_PaX](https://forum.ansible.com/u/Three_PaX)\
**Post date:** [March 14, 2021, 10:24pm UTC](https://forum.ansible.com/t/loop-on-ios-fact-error/34779/3 "2021-03-14T22:24:54Z")

</div>

hello Dick Visser

here is the debug

ok: [Paris] =\> {  
“ansible\_net\_interfaces”: {  
“ansible\_facts”: {  
“ansible\_net\_all\_ipv4\_addresses”: [  
“192.168.2.55”,  
“192.168.4.20”,  
“192.168.3.100”  
],  
“ansible\_net\_all\_ipv6\_addresses”: ,  
“ansible\_net\_api”: “cliconf”,  
“ansible\_net\_config”: “!\n! Last configuration change at 23:37:51 UTC Sat Mar 13 2021 by admin\n!\nversion 15.6\nservice timestamps debug datetime msec\nservice timestamps log datetime msec\nno service password-encryption\n!\nhostname Paris\n!\nboot-start-marker\nboot-end-marker\n!\n!\n!\nno aaa new-model\nethernet lmi ce\n!\n!\n!\nmmi polling-interval 60\nno mmi auto-configure\nno mmi pvc\nmmi snmp-timeout 180\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\nip domain name [paris.com](http://paris.com)\nip cef\nno ipv6 cef\n!\nmultilink bundle-name authenticated\n!\n!\n!\n!\nusername admin privilege 15 secret 5 $1$3SCD$Q2CVm6CjtUh/n3qogw04T/\n!\nredundancy\n!\n!\n! \n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\ninterface GigabitEthernet0/0\n ip address 192.168.2.55 255.255.255.0\n duplex full\n speed auto\n media-type rj45\n!\ninterface GigabitEthernet0/1\n ip address 192.168.4.20 255.255.255.0\n duplex auto\n speed auto\n media-type rj45\n!\ninterface GigabitEthernet0/2\n description ProBTP\n mtu 512\n ip address 192.168.3.100 255.255.255.0\n duplex half\n speed 100\n media-type rj45\n!\ninterface GigabitEthernet0/3\n no ip address\n shutdown\n duplex auto\n speed auto\n media-type rj45\n!\nip forward-protocol nd\n!\n!\nno ip http server\nno ip http secure-server\nip route 0.0.0.0 0.0.0.0 192.168.2.33\nip route 192.168.2.0 255.255.255.0 GigabitEthernet0/0\nip route 192.168.4.0 255.255.255.0 GigabitEthernet0/1\nip ssh version 2\nip ssh pubkey-chain\n username admin\n key-hash ssh-rsa F3BD34AD0E847EFC11B5E8B4E1868753 root@user-virtual-machine\n!\n!\n!\n!\ncontrol-plane\n!\nbanner exec ^C\n\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n\* IOSv is strictly limited to use for evaluation, demonstration and IOS _\n_ education. IOSv is provided as-is and is not supported by Cisco’s _\n_ Technical Advisory Center. Any use or disclosure, in whole or in part, _\n_ of the IOSv Software or Documentation to any third party for any _\n_ purposes is expressly prohibited except as otherwise authorized by _\n_ Cisco in writing. _\n_\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*^C\nbanner incoming ^C\n\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n\* IOSv is strictly limited to use for evaluation, demonstration and IOS _\n_ education. IOSv is provided as-is and is not supported by Cisco’s _\n_ Technical Advisory Center. Any use or disclosure, in whole or in part, _\n_ of the IOSv Software or Documentation to any third party for any _\n_ purposes is expressly prohibited except as otherwise authorized by _\n_ Cisco in writing. _\n_\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*^C\nbanner login ^C\n\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n\* IOSv is strictly limited to use for evaluation, demonstration and IOS _\n_ education. IOSv is provided as-is and is not supported by Cisco’s _\n_ Technical Advisory Center. Any use or disclosure, in whole or in part, _\n_ of the IOSv Software or Documentation to any third party for any _\n_ purposes is expressly prohibited except as otherwise authorized by _\n_ Cisco in writing.  
_\n_\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*^C\n!\nline con 0\nline aux 0\nline vty 0 4\n login local\n transport input ssh\n!\nno scheduler allocate\n!\nend”,  
“ansible\_net\_filesystems”: [  
“flash0:”  
],  
“ansible\_net\_filesystems\_info”: {  
“flash0:”: {  
“spacefree\_kb”: 1947660.0,  
“spacetotal\_kb”: 2092496.0  
}  
},  
“ansible\_net\_gather\_network\_resources”: ,  
“ansible\_net\_gather\_subset”: [  
“default”,  
“hardware”,  
“interfaces”,  
“config”  
],  
“ansible\_net\_hostname”: “Paris”,  
“ansible\_net\_image”: “flash0:/vios-adventerprisek9-m”,  
“ansible\_net\_interfaces”: {  
“GigabitEthernet0/0”: {  
“bandwidth”: 1000000,  
“description”: null,  
“duplex”: “Full”,  
“ipv4”: [  
{  
“address”: “192.168.2.55”,  
“subnet”: “24”  
}  
],  
“lineprotocol”: “up”,  
“macaddress”: “5000.0003.0000”,  
“mediatype”: “RJ45”,  
“mtu”: 1500,  
“operstatus”: “up”,  
“type”: “iGbE”  
},  
“GigabitEthernet0/1”: {  
“bandwidth”: 1000000,  
“description”: null,  
“duplex”: null,  
“ipv4”: [  
{  
“address”: “192.168.4.20”,  
“subnet”: “24”  
}  
],  
“lineprotocol”: “up”,  
“macaddress”: “5000.0003.0001”,  
“mediatype”: “RJ45”,  
“mtu”: 1500,  
“operstatus”: “up”,  
“type”: “iGbE”  
},  
“GigabitEthernet0/2”: {  
“bandwidth”: 100000,  
“description”: “ProBTP”,  
“duplex”: “Half”,  
“ipv4”: [  
{  
“address”: “192.168.3.100”,  
“subnet”: “24”  
}  
],  
“lineprotocol”: “up”,  
“macaddress”: “5000.0003.0002”,  
“mediatype”: “RJ45”,  
“mtu”: 512,  
“operstatus”: “up”,  
“type”: “iGbE”  
},  
“GigabitEthernet0/3”: {  
“bandwidth”: 1000000,  
“description”: null,  
“duplex”: “Auto”,  
“ipv4”: ,  
“lineprotocol”: “down”,  
“macaddress”: “5000.0003.0003”,  
“mediatype”: “RJ45”,  
“mtu”: 1500,  
“operstatus”: “administratively down”,  
“type”: “iGbE”  
}  
},  
“ansible\_net\_iostype”: “IOS”,  
“ansible\_net\_memfree\_mb”: 759444.49609375,  
“ansible\_net\_memtotal\_mb”: 839230.875,  
“ansible\_net\_model”: “IOSv”,  
“ansible\_net\_neighbors”: {  
“GigabitEthernet0/0”: [  
{  
“host”: “NexSwitch(9DSNVT707QU)”,  
“port”: “Ethernet1/7”  
}  
]  
},  
“ansible\_net\_python\_version”: “3.6.9”,  
“ansible\_net\_serialnum”: “91TG7P06MKBY2DUFA5LYV”,  
“ansible\_net\_system”: “ios”,  
“ansible\_net\_version”: “15.6(2)T”,  
“ansible\_network\_resources”: {}  
},  
“changed”: false,  
“failed”: false,

“warnings”: [

“default value for `gather_subset` will be changed to `min` from `!config` v2.11 onwards”  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![Three\_PaX](https://avatars.discourse-cdn.com/v4/letter/t/9dc877/32.png) [@Three\_PaX](https://forum.ansible.com/u/Three_PaX)\
**Post date:** [March 15, 2021, 2:58am UTC](https://forum.ansible.com/t/loop-on-ios-fact-error/34779/4 "2021-03-15T02:58:48Z")

</div>

hello Guyz

i fixit

- name: Play on switch  
hosts: Paris  
gather\_facts: yes

tasks:

- name: set fact  
ios\_facts:  
gather\_subset: all  
register: out \<====== [[[[[[the error was the name of my output i named it “ansible\_net\_interfaces” and ansible saw it like a dictionnary]]]]]]]

- debug:  
var: out

- name: Ajouter ligne COS\_in  
ios\_config:  
lines:

- service-policy input COS-IN  
parents: “interface {{ item.key }}”  
with\_dict: “{{ ansible\_net\_interfaces }}”  
when: “(item.value.operstatus == ‘up’)” \<==== [[[[[[and here i add the parentheses]]]]]]

it’s working like a charm
