loop on ios fact error

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

Where is the output of the debug task?

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\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”
]
}
}

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