Как использовать модуль ansible ios_l2_interfaces для l oop через ios фактов? - PullRequest
0 голосов
/ 24 января 2020

Я хочу выполнить l oop через каждый интерфейс на коммутаторе Cisco IOS и установить конкретную c конфигурацию уровня 2, если описание соответствует определенному слову (-ap- обозначает точку доступа).

Это пьеса:

---
- name: Cisco Layer 2 Interface
  hosts: test
  strategy: free
  vars:
   ansible_command_timeout: 60
   desc_search: "-ap-"
  tasks:
   - name: IOS facts
     ios_facts:
      gather_subset:
       - '!all'
       - '!min'
      gather_network_resources:
       - 'interfaces'
   - name: Layer 2 config
     ios_l2_interfaces:
      config:
       - name: "{{ item.key }}"
         trunk:
          allowed_vlans: 10,20,30,40
          native_vlan: 10
          encapsulation: dot1q
      state: replaced
     loop: "{{ ansible_net_interfaces|dict2items }}"
     when: item.value.description is search(desc_search)
...

Получение фактов работает нормально. Однако модуль ios_l2_interfaces завершается ошибкой со следующей ошибкой. Кажется, ключ - name: item.key не работает, однако в сообщении об ошибке четко указывается, что он есть.

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'get'
failed: [demo-sw-02.nb.edeka.net] (item={'key': u'GigabitEthernet1/0/24', 'value': {u'macaddress': u'xxxx.xxxx.xxxx', u'lineprotocol': None, u'description': u'#demo-ap-02', u'duplex': None, u'mediatype': u'10/100/1000BaseTX', u'mtu': 1500, u'operstatus': u'up', u'bandwidth': 1000000, u'ipv4': [], u'type': u'Gigabit Ethernet'}}) => {
    "ansible_loop_var": "item",
    "changed": false,
    "item": {
        "key": "GigabitEthernet1/0/24",
        "value": {
            "bandwidth": 1000000,
            "description": "#demo-ap-02",
            "duplex": null,
            "ipv4": [],
            "lineprotocol": null,
            "macaddress": "xxxx.xxxx.xxxx",
            "mediatype": "10/100/1000BaseTX",
            "mtu": 1500,
            "operstatus": "up",
            "type": "Gigabit Ethernet"
        }
    },
    "rc": 1
}

MSG:

MODULE FAILURE
See stdout/stderr for the exact error


MODULE_STDERR:

Traceback (most recent call last):
  File "/home/ansible/.ansible/tmp/ansible-local-7161cuIEBE/ansible-tmp-1579863214.5-251145517474981/AnsiballZ_ios_l2_interfaces.py", line 102, in <module>
    _ansiballz_main()
  File "/home/ansible/.ansible/tmp/ansible-local-7161cuIEBE/ansible-tmp-1579863214.5-251145517474981/AnsiballZ_ios_l2_interfaces.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/ansible/.ansible/tmp/ansible-local-7161cuIEBE/ansible-tmp-1579863214.5-251145517474981/AnsiballZ_ios_l2_interfaces.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible.modules.network.ios.ios_l2_interfaces', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib64/python2.7/runpy.py", line 188, in run_module
    fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/tmp/ansible_ios_l2_interfaces_payload_CAXtV1/ansible_ios_l2_interfaces_payload.zip/ansible/modules/network/ios/ios_l2_interfaces.py", line 364, in <module>
  File "/tmp/ansible_ios_l2_interfaces_payload_CAXtV1/ansible_ios_l2_interfaces_payload.zip/ansible/modules/network/ios/ios_l2_interfaces.py", line 359, in main
  File "/tmp/ansible_ios_l2_interfaces_payload_CAXtV1/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/network/ios/config/l2_interfaces/l2_interfaces.py", line 63, in execute_module
  File "/tmp/ansible_ios_l2_interfaces_payload_CAXtV1/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/network/ios/config/l2_interfaces/l2_interfaces.py", line 88, in set_config
  File "/tmp/ansible_ios_l2_interfaces_payload_CAXtV1/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/network/ios/config/l2_interfaces/l2_interfaces.py", line 113, in set_state
  File "/tmp/ansible_ios_l2_interfaces_payload_CAXtV1/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/network/ios/config/l2_interfaces/l2_interfaces.py", line 134, in _state_replaced
  File "/tmp/ansible_ios_l2_interfaces_payload_CAXtV1/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/network/ios/utils/utils.py", line 75, in filter_dict_having_none_value
AttributeError: 'NoneType' object has no attribute 'get'

Я использую ansible 2.9.4.

...