HPENetworking / hpe-cw7-ansible

HPE Comware 7 Ansible
Other
21 stars 18 forks source link

comware_vxlan_svc_instance not idempotent #2

Closed p3rdu closed 8 months ago

p3rdu commented 1 year ago

Hi,

We're trying to make up a playbook for setting VXLAN BGP EVPN fabric but while running tasks for service instances they run ok when configured for first time but give error for second time.

TASK [configure Ethernet Service Instances] *****************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: bad argument type: NoneType(None)
failed: [leaf1] (item=[{'name': 'Ten-GigabitEthernet1/0/3', 'service_instances': [{'id': 1, 'encap': 'untagged', 'vsi': 'vmware'}]}, {'id': 1, 'encap': 'untagged', 'vsi': 'vmware'}]) => {"ansible_loop_var": "item", "changed": false, "item": [{"name": "Ten-GigabitEthernet1/0/3", "service_instances": [{"encap": "untagged", "id": 1, "vsi": "vmware"}]}, {"encap": "untagged", "id": 1, "vsi": "vmware"}], 
"module_stderr": "Traceback (most recent call last):\n  
File \"/home/user/.ansible/tmp/ansible-tmp-1672224685.5352736-98961742194061/AnsiballZ_comware_vxlan_svc_instance.py\", line 102, in <module>\n    _ansiballz_main()\n  
File \"/home/user/.ansible/tmp/ansible-tmp-1672224685.5352736-98961742194061/AnsiballZ_comware_vxlan_svc_instance.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  
File \"/home/user/.ansible/tmp/ansible-tmp-1672224685.5352736-98961742194061/AnsiballZ_comware_vxlan_svc_instance.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.comware_vxlan_svc_instance', init_globals=None, run_name='__main__', alter_sys=True)\n  
File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n 
File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n
File \"/tmp/ansible_comware_vxlan_svc_instance_payload_vnnwulln/ansible_comware_vxlan_svc_instance_payload.zip/ansible/modules/comware_vxlan_svc_instance.py\", line 307, in <module>\n  
File \"/tmp/ansible_comware_vxlan_svc_instance_payload_vnnwulln/ansible_comware_vxlan_svc_instance_payload.zip/ansible/modules/comware_vxlan_svc_instance.py\", line 273, in main\n  
File \"/usr/local/lib/python3.8/dist-packages/pyhpecw7-0.0.11-py3.8.egg/pyhpecw7/features/vxlan.py\", line 717, in build\n    return self._build_config(state='present', stage=stage, **kvargs)\n  File \"/usr/local/lib/python3.8/dist-packages/pyhpecw7-0.0.11-py3.8.egg/pyhpecw7/features/vxlan.py\", line 734, in _build_config\n    self._build_xconnect(operation, self.jindex, stage=stage, **kvargs)\n  
File \"/usr/local/lib/python3.8/dist-packages/pyhpecw7-0.0.11-py3.8.egg/pyhpecw7/features/vxlan.py\", line 769, in _build_xconnect\n    EC.AccessMode(MAP.get(kvargs.get('access_mode')))\n  File \"src/lxml/builder.py\", line 226, in lxml.builder.ElementMaker.__call__\nTypeError: bad argument type: NoneType(None)\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Play is this:

 - name: configure Ethernet Service Instances
   comware_vxlan_svc_instance:
     interface: "{{ item.0.name }}"
     instance: "{{ item.1.id }}"
     encap: "{{ item.1.encap }}"
     vlanid: "{{ item.1.vlan|default()}}"
     vsi: "{{ item.1.vsi }}"
     username: "{{ username }}"
     password: "{{ password }}"
     hostname: "{{ ansible_host }}"
   loop: "{{ host_interfaces|default({})|subelements('service_instances') }}"

And host vars

host_interfaces:
  - name: Ten-GigabitEthernet1/0/3
    service_instances: 
      - id: 1
        encap: untagged
        vsi: vmware
p3rdu commented 1 year ago

I've now found out that this seems to be an issue only on service_instances with untagged encapsulation. Another item under same variable

- name: Ten-GigabitEthernet1/0/48
    service_instances: 
      - id: 1
        encap: s-vid
        vlan: 196
        vsi: vmware

outputs correctly

ok: [leaf1] => (item=[{'name': 'Ten-GigabitEthernet1/0/48', 'service_instances': [{'id': 1, 'encap': 's-vid', 'vlan': 196, 'vsi': 'vmware'}]}, {'id': 1, 'encap': 's-vid', 'vlan': 196, 'vsi': 'vmware'}])
flycoolman commented 1 year ago

Could you please replicate the issue per the steps below and provide the data:

  1. show the config before running the not-working playbook
  2. run the not-working playbook to replicate the issue and then show the config
  3. show the config before running the working playbook
  4. run the working playbook and then show the config
p3rdu commented 1 year ago

The problem only appears when running the play for a second time or any subsequent time. Hence the problem lies in idempotence. 1.

<hp5490-leaf1>dis current-configuration interface Ten-GigabitEthernet 1/0/3
#
interface Ten-GigabitEthernet1/0/3
 port link-mode bridge
#
return

2. Then I applied the play present in my first post with these variables (host_vars/leaf1.yml)

ansible_host: hp5490-leaf1
interfaces:
  Ten-GigabitEthernet1/0/1: 10.1.1.1/31
  Ten-GigabitEthernet1/0/2: 10.2.1.1/31
  LoopBack0: 10.0.1.0/32
host_interfaces:
  - name: Ten-GigabitEthernet1/0/3
    service_instances: 
      - id: 1
        encap: untagged
        vsi: vmware
      - id: 2
        encap: s-vid
        vlan: 2
        vsi: vmware-vmotion    
  - name: Ten-GigabitEthernet1/0/48
    service_instances: 
      - id: 1
        encap: s-vid
        vlan: 196
        vsi: vmware

Executing command ansible-playbook ethernet-service-instances.yml -l leaf1

TASK [configure Ethernet Service Instances] ********************************************************************************************************************
changed: [leaf1] => (item=[{'name': 'Ten-GigabitEthernet1/0/3', 'service_instances': [{'id': 1, 'encap': 'untagged', 'vsi': 'vmware'}, {'id': 2, 'encap': 's-vid', 'vlan': 2, 'vsi': 'vmware-vmotion'}]}, {'id': 1, 'encap': 'untagged', 'vsi': 'vmware'}])
changed: [leaf1] => (item=[{'name': 'Ten-GigabitEthernet1/0/3', 'service_instances': [{'id': 1, 'encap': 'untagged', 'vsi': 'vmware'}, {'id': 2, 'encap': 's-vid', 'vlan': 2, 'vsi': 'vmware-vmotion'}]}, {'id': 2, 'encap': 's-vid', 'vlan': 2, 'vsi': 'vmware-vmotion'}])
changed: [leaf1] => (item=[{'name': 'Ten-GigabitEthernet1/0/48', 'service_instances': [{'id': 1, 'encap': 's-vid', 'vlan': 196, 'vsi': 'vmware'}]}, {'id': 1, 'encap': 's-vid', 'vlan': 196, 'vsi': 'vmware'}])

Configuration for XGE1/0/3 is now

<hp5490-leaf1>dis current-configuration interface Ten-GigabitEthernet 1/0/3
#
interface Ten-GigabitEthernet1/0/3
 port link-mode bridge
 #
 service-instance 1
  encapsulation untagged
  xconnect vsi vmware
 #
 service-instance 2
  encapsulation s-vid 2
  xconnect vsi vmware-vmotion
#
return

Then I apply the play again

TASK [create Ethernet Service Instances] ********************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: bad argument type: NoneType(None)
failed: [leaf1] (item=[{'name': 'Ten-GigabitEthernet1/0/3', 'service_instances': [{'id': 1, 'encap': 'untagged', 'vsi': 'vmware'}, {'id': 2, 'encap': 's-vid', 'vlan': 2, 'vsi': 'vmware-vmotion'}]}, {'id': 1, 'encap': 'untagged', 'vsi': 'vmware'}]) => {"ansible_loop_var": "item", "changed": false, "item": [{"name": "Ten-GigabitEthernet1/0/3", "service_instances": [{"encap": "untagged", "id": 1, "vsi": "vmware"}, {"encap": "s-vid", "id": 2, "vlan": 2, "vsi": "vmware-vmotion"}]}, {"encap": "untagged", "id": 1, "vsi": "vmware"}], "module_stderr": "Traceback (most recent call last):\n  File \"/home/myuser/.ansible/tmp/ansible-tmp-1672822005.7315423-167672753980290/AnsiballZ_comware_vxlan_svc_instance.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/myuser/.ansible/tmp/ansible-tmp-1672822005.7315423-167672753980290/AnsiballZ_comware_vxlan_svc_instance.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/myuser/.ansible/tmp/ansible-tmp-1672822005.7315423-167672753980290/AnsiballZ_comware_vxlan_svc_instance.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.comware_vxlan_svc_instance', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_comware_vxlan_svc_instance_payload_r13lcud9/ansible_comware_vxlan_svc_instance_payload.zip/ansible/modules/comware_vxlan_svc_instance.py\", line 307, in <module>\n  File \"/tmp/ansible_comware_vxlan_svc_instance_payload_r13lcud9/ansible_comware_vxlan_svc_instance_payload.zip/ansible/modules/comware_vxlan_svc_instance.py\", line 273, in main\n  File \"/usr/local/lib/python3.8/dist-packages/pyhpecw7-0.0.11-py3.8.egg/pyhpecw7/features/vxlan.py\", line 717, in build\n    return self._build_config(state='present', stage=stage, **kvargs)\n  File \"/usr/local/lib/python3.8/dist-packages/pyhpecw7-0.0.11-py3.8.egg/pyhpecw7/features/vxlan.py\", line 734, in _build_config\n    self._build_xconnect(operation, self.jindex, stage=stage, **kvargs)\n  File \"/usr/local/lib/python3.8/dist-packages/pyhpecw7-0.0.11-py3.8.egg/pyhpecw7/features/vxlan.py\", line 769, in _build_xconnect\n    EC.AccessMode(MAP.get(kvargs.get('access_mode')))\n  File \"src/lxml/builder.py\", line 226, in lxml.builder.ElementMaker.__call__\nTypeError: bad argument type: NoneType(None)\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
ok: [leaf1] => (item=[{'name': 'Ten-GigabitEthernet1/0/3', 'service_instances': [{'id': 1, 'encap': 'untagged', 'vsi': 'vmware'}, {'id': 2, 'encap': 's-vid', 'vlan': 2, 'vsi': 'vmware-vmotion'}]}, {'id': 2, 'encap': 's-vid', 'vlan': 2, 'vsi': 'vmware-vmotion'}])
ok: [leaf1] => (item=[{'name': 'Ten-GigabitEthernet1/0/48', 'service_instances': [{'id': 1, 'encap': 's-vid', 'vlan': 196, 'vsi': 'vmware'}]}, {'id': 1, 'encap': 's-vid', 'vlan': 196, 'vsi': 'vmware'}])

The untagged Ethernet service instance fails, others not.

flycoolman commented 1 year ago

The issue has been replicated in the lab. We are investigating the root cause.

flycoolman commented 1 year ago

There is a workaround or requirement (check all the examples in the document) to put all the parameters in single line. An example shows below. @p3rdu Please test and let me know the result.

- name: VLAN Automation with Ansible on HP Com7 Devices hosts: switches gather_facts: no connection: local vars_files: - interface.yml

 tasks:

 - name:  enable l2vpn
   comware_l2vpn_global: state=enabled username={{ username }} password={{ password }} hostname={{ inventory_hostname }}

 - name:  config interface
   comware_vxlan_svc_instance: interface=Fo3/1/25 vsi=1 instance=10 encap=s-vid vlanid=10 state=present username={{ username }} password={{ password }} hostname={{ inventory_hostname }}

 - name:  config interface
   comware_vxlan_svc_instance: interface=Fo3/1/25 vsi=2 instance=100 encap=untagged access_mode=ethernet state=present username={{ username }} password={{ password }} hostname={{ inventory_hostname }}