CiscoDevNet / ansible-dcnm

Apache License 2.0
47 stars 37 forks source link

dcnm_rest failed with ansible.netcommon:5.0.0 #209

Closed dsx1123 closed 1 year ago

dsx1123 commented 1 year ago

Community Note

Ansible Version and collection version

ansible [core 2.12.10]
  config file = /root/.ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/virtualenv/ansible/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /root/virtualenv/ansible/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 3.1.2
  libyaml = True
# /root/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
ansible.netcommon 5.0.0
ansible.posix     1.3.0
ansible.utils     2.9.0
arista.avd        3.7.0
arista.cvp        3.4.0
arista.eos        3.1.0
cisco.aci         2.1.0
cisco.dcnm        3.0.0
cisco.mso         1.2.0
cisco.nd          0.1.2
cisco.nxos        4.0.1

DCNM version

Affected module(s)

Ansible Playbook

# Copy-paste your anisble playbook here 
- name: build fabric
  hosts: ndfc2
  gather_facts: false
  collections:
    - cisco.dcnm
  vars:
    fabric: "{{ fabric_n9kv }}"
  tasks:
    - name: Get all fabrics
      dcnm_rest:
        method: GET
        path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics"
      register: res_fabrics

Debug Output

ansible-playbook [core 2.12.10]
  config file = /root/.ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/virtualenv/ansible/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /root/virtualenv/ansible/bin/ansible-playbook
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 3.1.2
  libyaml = True
Using /root/.ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
Loading collection cisco.dcnm from /root/.ansible/collections/ansible_collections/cisco/dcnm
Loading callback plugin default of type stdout, v2.0 from /root/virtualenv/ansible/lib/python3.9/site-packages/ansible/plugins/callback/default.py
Loading collection ansible.posix from /root/.ansible/collections/ansible_collections/ansible/posix
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Loading callback plugin ansible.posix.profile_tasks of type aggregate, v2.0 from /root/.ansible/collections/ansible_collections/ansible/posix/plugins/callback/profile_tasks.py

PLAYBOOK: build.yml ***************************************************************************************************************************************************************
Positional arguments: build.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/etc/ansible/hosts',)
forks: 5
1 plays in build.yml

PLAY [build fabric] ***************************************************************************************************************************************************************
Trying secret FileVaultSecret(filename='/root/.vault_pass') for vault_id=default
META: ran handlers

TASK [Get all fabrics] ************************************************************************************************************************************************************
task path: /root/workspace/ansible/dcnm/lab_n9kv/build.yml:9
Friday 10 March 2023  12:07:29 -0800 (0:00:00.044)       0:00:00.044 **********
redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
Loading collection ansible.netcommon from /root/.ansible/collections/ansible_collections/ansible/netcommon
Loading collection ansible.utils from /root/.ansible/collections/ansible_collections/ansible/utils
<shdu-ndfc-2.cisco.com> attempting to start connection
<shdu-ndfc-2.cisco.com> using connection plugin ansible.netcommon.httpapi
Found ansible-connection at path /root/virtualenv/ansible/bin/ansible-connection
<shdu-ndfc-2.cisco.com> local domain socket does not exist, starting it
<shdu-ndfc-2.cisco.com> control socket path is /root/.ansible/pc/b51965b6eb
<shdu-ndfc-2.cisco.com> redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
<shdu-ndfc-2.cisco.com> Loading collection ansible.netcommon from /root/.ansible/collections/ansible_collections/ansible/netcommon
<shdu-ndfc-2.cisco.com> Loading collection ansible.utils from /root/.ansible/collections/ansible_collections/ansible/utils
<shdu-ndfc-2.cisco.com> Loading collection cisco.dcnm from /root/.ansible/collections/ansible_collections/cisco/dcnm
<shdu-ndfc-2.cisco.com> local domain socket listeners started successfully
<shdu-ndfc-2.cisco.com> loaded API plugin ansible_collections.cisco.dcnm.plugins.httpapi.dcnm from path /root/.ansible/collections/ansible_collections/cisco/dcnm/plugins/httpapi/dcnm.py for platform type cisco.dcnm.dcnm
<shdu-ndfc-2.cisco.com>
<shdu-ndfc-2.cisco.com> local domain socket path is /root/.ansible/pc/b51965b6eb
<shdu-ndfc-2.cisco.com> ESTABLISH LOCAL CONNECTION FOR USER: root
<shdu-ndfc-2.cisco.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-6632172el1ibzd `"&& mkdir "` echo /root/.ansible/tmp/ansible-local-6632172el1ibzd/ansible-tmp-1678478850.1640809-663221-88431691388340 `" && echo ansible-tmp-1678478850.1640809-663221-88431691388340="` echo /root/.ansible/tmp/ansible-local-6632172el1ibzd/ansible-tmp-1678478850.1640809-663221-88431691388340 `" ) && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/cisco/dcnm/plugins/modules/dcnm_rest.py
<shdu-ndfc-2.cisco.com> PUT /root/.ansible/tmp/ansible-local-6632172el1ibzd/tmp9upj3aqz TO /root/.ansible/tmp/ansible-local-6632172el1ibzd/ansible-tmp-1678478850.1640809-663221-88431691388340/AnsiballZ_dcnm_rest.py
<shdu-ndfc-2.cisco.com> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-6632172el1ibzd/ansible-tmp-1678478850.1640809-663221-88431691388340/ /root/.ansible/tmp/ansible-local-6632172el1ibzd/ansible-tmp-1678478850.1640809-663221-88431691388340/AnsiballZ_dcnm_rest.py && sleep 0'
<shdu-ndfc-2.cisco.com> EXEC /bin/sh -c '/root/virtualenv/ansible/bin/python /root/.ansible/tmp/ansible-local-6632172el1ibzd/ansible-tmp-1678478850.1640809-663221-88431691388340/AnsiballZ_dcnm_rest.py && sleep 0'
<shdu-ndfc-2.cisco.com> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-6632172el1ibzd/ansible-tmp-1678478850.1640809-663221-88431691388340/ > /dev/null 2>&1 && sleep 0'
fatal: [shdu-ndfc-2.cisco.com]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "data": null,
            "method": "GET",
            "path": "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics"
        }
    },
    "msg": {
        "DATA": {
            "error": "Internal Server Error",
            "path": "/rest/control/fabrics",
            "status": 500,
            "timestamp": 1678478850602
        },
        "MESSAGE": "Internal Server Error",
        "METHOD": "GET",
        "REQUEST_PATH": "https://shdu-ndfc-2.cisco.com:443/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics",
        "RETURN_CODE": 500
    }
}

PLAY RECAP ************************************************************************************************************************************************************************
shdu-ndfc-2.cisco.com      : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Friday 10 March 2023  12:07:30 -0800 (0:00:01.099)       0:00:01.144 **********
===============================================================================
Get all fabrics ------------------------------------------------------------------------------------------------------------------------------------------------------------ 1.10s
/root/workspace/ansible/dcnm/lab_n9kv/build.yml:9 --------------------------------------------------------------------------------------------------------------------------------

Expected Behavior

the same playbook works with any ansible.netcommon version < 5

Actual Behavior

rest module failed

Steps to Reproduce

References

akinross commented 1 year ago

Similar issue was seen in the mso ansible collection: https://github.com/CiscoDevNet/ansible-mso/issues/340.

There we identified it as an issue caused by the ansible.netcommon collection. A fix has been made for this in This PR fixes it https://github.com/ansible-collections/ansible.netcommon/pull/523.

You could try to install 5.0.1-dev ( install collection directly from git ) version to check if this removes the issue.

mikewiebe commented 1 year ago

@akinross Thanks for the suggestion! I will try it out

mikewiebe commented 1 year ago

@akinross That was it. I tested with 5.0.1-dev and it's working fine now. Thanks for the heads up!

With 5.0.0:

(ansible_py380) ➜  netcommon git:(2be63bd) git status
HEAD detached at 5.0.0
nothing to commit, working tree clean
(ansible_py380) ➜  netcommon git:(2be63bd) 
(ansible_py3_9_16) ➜  dcnm_fabric git:(develop) ✗ ansible-playbook -i dcnm_hosts.yaml dcnm_tests.yaml
[WARNING]: running playbook inside collection cisco.dcnm

PLAY [dcnm] ****************************************************************************************************************************************************************

TASK [set_fact] ************************************************************************************************************************************************************
ok: [rtp-ndfc1.cisco.com]

TASK [set_fact] ************************************************************************************************************************************************************
ok: [rtp-ndfc1.cisco.com]

TASK [Test dcnm_rest module] ***********************************************************************************************************************************************
fatal: [rtp-ndfc1.cisco.com]: FAILED! => {"changed": false, "msg": {"DATA": {"error": "Internal Server Error", "path": "/rest/control/fabrics", "status": 500, "timestamp": 1679492271540}, "MESSAGE": "Internal Server Error", "METHOD": "GET", "REQUEST_PATH": "https://rtp-ndfc1.cisco.com:443/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics", "RETURN_CODE": 500}}

PLAY RECAP *****************************************************************************************************************************************************************
rtp-ndfc1.cisco.com        : ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

(ansible_py3_9_16) ➜  dcnm_fabric git:(develop) ✗ 

With 5.0.1-dev:

(ansible_py380) ➜  netcommon git:(main) cat galaxy.yml| grep version
version: 5.0.1-dev
(ansible_py380) ➜  netcommon git:(main) 
(ansible_py3_9_16) ➜  dcnm_fabric git:(develop) ✗ ansible-playbook -i dcnm_hosts.yaml dcnm_tests.yaml   
[WARNING]: running playbook inside collection cisco.dcnm

PLAY [dcnm] ****************************************************************************************************************************************************************

TASK [set_fact] ************************************************************************************************************************************************************
ok: [rtp-ndfc1.cisco.com]

TASK [set_fact] ************************************************************************************************************************************************************
ok: [rtp-ndfc1.cisco.com]

TASK [Test dcnm_rest module] ***********************************************************************************************************************************************
ok: [rtp-ndfc1.cisco.com]

PLAY RECAP *****************************************************************************************************************************************************************
rtp-ndfc1.cisco.com        : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

(ansible_py3_9_16) ➜  dcnm_fabric git:(develop) ✗ 
mikewiebe commented 1 year ago

Will close this issue once ansible.netcommon version 5.0.1 is published on Galaxy.

praveenramoorthy commented 1 year ago

This issue has been resolved in net common 5.0.1 and later releases. Closing this issue