Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing RPC with filters returns The error was: AttributeError: 'JuniperJunosModule' object has no attribute '_check_type_dict' #620

Closed
mamathac opened this issue Jun 9, 2023 · 3 comments

Comments

@mamathac
Copy link

mamathac commented Jun 9, 2023

juniper.device collection and Python libraries version


root@masterhost:~# ansible-galaxy collection list

# /usr/local/lib/python3.8/dist-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    2.1.0
ansible.netcommon             2.5.1
ansible.posix                 1.3.0
ansible.utils                 2.5.0
ansible.windows               1.9.0
arista.eos                    3.1.0
awx.awx                       19.4.0
azure.azcollection            1.11.0
check_point.mgmt              2.2.2
chocolatey.chocolatey         1.2.0
cisco.aci                     2.1.0
cisco.asa                     2.1.0
cisco.intersight              1.0.18
cisco.ios                     2.7.1
cisco.iosxr                   2.7.0
cisco.ise                     1.2.1
cisco.meraki                  2.6.0
cisco.mso                     1.3.0
cisco.nso                     1.0.3
cisco.nxos                    2.9.0
cisco.ucs                     1.6.0
cloud.common                  2.1.0
cloudscale_ch.cloud           2.2.0
community.aws                 2.3.0
community.azure               1.1.0
community.ciscosmb            1.0.4
community.crypto              2.2.2
community.digitalocean        1.15.1
community.dns                 2.0.7
community.docker              2.2.0
community.fortios             1.0.0
community.general             4.5.0
community.google              1.0.0
community.grafana             1.3.2
community.hashi_vault         2.3.0
community.hrobot              1.2.2
community.kubernetes          2.0.1
community.kubevirt            1.0.0
community.libvirt             1.0.2
community.mongodb             1.3.2
community.mysql               2.3.4
community.network             3.0.0
community.okd                 2.1.0
community.postgresql          1.7.0
community.proxysql            1.3.1
community.rabbitmq            1.1.0
community.routeros            2.0.0
community.skydive             1.0.0
community.sops                1.2.0
community.vmware              1.17.1
community.windows             1.9.0
community.zabbix              1.5.1
containers.podman             1.9.1
cyberark.conjur               1.1.0
cyberark.pas                  1.0.13
dellemc.enterprise_sonic      1.1.0
dellemc.openmanage            4.4.0
dellemc.os10                  1.1.1
dellemc.os6                   1.0.7
dellemc.os9                   1.0.4
f5networks.f5_modules         1.14.0
fortinet.fortimanager         2.1.4
fortinet.fortios              2.1.4
frr.frr                       1.0.3
gluster.gluster               1.0.2
google.cloud                  1.0.2
hetzner.hcloud                1.6.0
hpe.nimble                    1.1.4
ibm.qradar                    1.0.3
infinidat.infinibox           1.3.3
infoblox.nios_modules         1.2.1
inspur.sm                     1.3.0
junipernetworks.junos         2.9.0
kubernetes.core               2.2.3
mellanox.onyx                 1.0.0
netapp.aws                    21.7.0
netapp.azure                  21.10.0
netapp.cloudmanager           21.14.0
netapp.elementsw              21.7.0
netapp.ontap                  21.16.0
netapp.storagegrid            21.9.0
netapp.um_info                21.8.0
netapp_eseries.santricity     1.2.13
netbox.netbox                 3.5.1
ngine_io.cloudstack           2.2.3
ngine_io.exoscale             1.0.0
ngine_io.vultr                1.1.0
openstack.cloud               1.7.0
openvswitch.openvswitch       2.1.0
ovirt.ovirt                   1.6.6
purestorage.flasharray        1.12.1
purestorage.flashblade        1.9.0
sensu.sensu_go                1.13.0
servicenow.servicenow         1.0.6
splunk.es                     1.0.2
t_systems_mms.icinga_director 1.27.1
theforeman.foreman            2.2.0
vyos.vyos                     2.7.0
wti.remote                    1.0.3

# /root/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
ansible.netcommon 5.1.1
ansible.utils     2.10.3
juniper.device    1.0.1

root@masterhost:~# ansible --version
ansible [core 2.12.3]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
  jinja version = 3.1.2
  libyaml = True

OS / Environment

NA

Summary

On running a playbook to filter an RPC with args , error occurs.

Steps to reproduce

Run the ansible playbook shown

---
- name: Testing Collections Persistent
  hosts: [SINGLE]
  connection: juniper.device.pyez
  gather_facts: no
  collections:
    - juniper.device
  
  tasks:
    - name: "Execute RPC with filters"
      rpc:
        rpcs:
           - "get-config"
        format: xml
        filter: <configuration><groups><name>re0</name></groups></configuration>
        attr: name=re0
      register: test1
      ignore_errors: True
      tags: rpc_a

Expected results

TASK [Execute RPC with filters] *****************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'JuniperJunosModule' object has no attribute '_check_type_dict'
fatal: [10.204.39.63]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-local-10778e55bheik/ansible-tmp-1686303814.916357-10983-36112855681718/AnsiballZ_rpc.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-local-10778e55bheik/ansible-tmp-1686303814.916357-10983-36112855681718/AnsiballZ_rpc.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-local-10778e55bheik/ansible-tmp-1686303814.916357-10983-36112855681718/AnsiballZ_rpc.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.rpc', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.rpc', _modlib_path=modlib_path),\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_rpc_payload_ubfvx0d3/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 631, in <module>\n  File \"/tmp/ansible_rpc_payload_ubfvx0d3/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 468, in main\n  File \"/tmp/ansible_rpc_payload_ubfvx0d3/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 935, in parse_arg_to_list_of_dicts\nAttributeError: 'JuniperJunosModule' object has no attribute '_check_type_dict'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
...ignoring

Actual results

root@masterhost:/etc/ansible# ansible-playbook /etc/ansible/ansible_collections_persistent_playbook.yaml -t p5 -vvv
ansible-playbook [core 2.12.3]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
  jinja version = 3.1.2
  libyaml = True
No config file found; using defaults
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
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.

PLAYBOOK: ansible_collections_persistent_playbook.yaml ****************************************************************************************
1 plays in /etc/ansible/ansible_collections_persistent_playbook.yaml
[WARNING]: Found variable using reserved name: timeout

PLAY [Testing Collections Persistent] *********************************************************************************************************
META: ran handlers

TASK [Execute RPC with filters] ***************************************************************************************************************
task path: /etc/ansible/ansible_collections_persistent_playbook.yaml:52
<10.204.39.63> ESTABLISH LOCAL CONNECTION FOR USER: root
<10.204.39.63> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-13069w8srdifn `"&& mkdir "` echo /root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702 `" && echo ansible-tmp-1686309288.536057-13074-219301847114702="` echo /root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702 `" ) && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/juniper/device/plugins/modules/rpc.py
<10.204.39.63> PUT /root/.ansible/tmp/ansible-local-13069w8srdifn/tmpkxif6svr TO /root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702/AnsiballZ_rpc.py
<10.204.39.63> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702/ /root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702/AnsiballZ_rpc.py && sleep 0'
<10.204.39.63> EXEC /bin/sh -c '/usr/bin/python3.8 /root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702/AnsiballZ_rpc.py && sleep 0'
<10.204.39.63> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702/AnsiballZ_rpc.py", line 107, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702/AnsiballZ_rpc.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702/AnsiballZ_rpc.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.rpc', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.rpc', _modlib_path=modlib_path),
  File "/usr/lib/python3.8/runpy.py", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_rpc_payload_3vvlvep2/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py", line 631, in <module>
  File "/tmp/ansible_rpc_payload_3vvlvep2/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py", line 468, in main
  File "/tmp/ansible_rpc_payload_3vvlvep2/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py", line 935, in parse_arg_to_list_of_dicts
AttributeError: 'JuniperJunosModule' object has no attribute '_check_type_dict'
fatal: [10.204.39.63]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702/AnsiballZ_rpc.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702/AnsiballZ_rpc.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-local-13069w8srdifn/ansible-tmp-1686309288.536057-13074-219301847114702/AnsiballZ_rpc.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.rpc', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.rpc', _modlib_path=modlib_path),\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_rpc_payload_3vvlvep2/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 631, in <module>\n  File \"/tmp/ansible_rpc_payload_3vvlvep2/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 468, in main\n  File \"/tmp/ansible_rpc_payload_3vvlvep2/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 935, in parse_arg_to_list_of_dicts\nAttributeError: 'JuniperJunosModule' object has no attribute '_check_type_dict'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
...ignoring
META: ran handlers
META: ran handlers

PLAY RECAP ************************************************************************************************************************************
10.204.39.63               : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1


@chidanandpujar
Copy link
Collaborator

@mamathac
Thanks ,
_check_type_dict looks to be deprecated according to following document
_check_type_dict() --> :func:ansible.module_utils.common.validation.check_type_dict

I will check and update .

Thanks & Regards
Chidanand

@chidanandpujar
Copy link
Collaborator

chidanandpujar commented Oct 17, 2023

Hi @mamathac
Thanks,
I have verified the fix and looks to be working fine and will create the pull request .
for persistent connection , ansible side fix is required ansible/ansible#79371 , which is not still merged by Ansible , we need to apply this fix and verify the playbook

~/ansible_release_v103/ansible-junos-stdlib/tests# ansible-playbook pb.juniper_junos_persistent_conn.yml -vvv
ansible-playbook [core 2.15.5]
  config file = /root/ansible_release_v103/ansible-junos-stdlib/tests/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/ansible_release_v103/venv/lib/python3.9/site-packages/ansible
  ansible collection location = /root/ansible_release_v103/ansible-junos-stdlib/ansible_collections
  executable location = /root/ansible_release_v103/venv/bin/ansible-playbook
  python version = 3.9.6 (default, Oct 18 2021, 17:33:10) [GCC 7.5.0] (/root/ansible_release_v103/venv/bin/python)
  jinja version = 3.1.2
  libyaml = True
Using /root/ansible_release_v103/ansible-junos-stdlib/tests/ansible.cfg as config file
host_list declined parsing /root/ansible_release_v103/ansible-junos-stdlib/tests/inventory as it did not pass its verify_file() method
script declined parsing /root/ansible_release_v103/ansible-junos-stdlib/tests/inventory as it did not pass its verify_file() method
auto declined parsing /root/ansible_release_v103/ansible-junos-stdlib/tests/inventory as it did not pass its verify_file() method
Parsed /root/ansible_release_v103/ansible-junos-stdlib/tests/inventory inventory source with ini plugin
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.

PLAYBOOK: pb.juniper_junos_persistent_conn.yml ****************************************************************************************************************************
1 plays in pb.juniper_junos_persistent_conn.yml

PLAY [Test juniper.device.rpc module] *************************************************************************************************************************************

TASK [Get Device Configuration for interface] *****************************************************************************************************************************
task path: /root/ansible_release_v103/ansible-junos-stdlib/tests/pb.juniper_junos_persistent_conn.yml:11
<10.53.102.143> ESTABLISH LOCAL CONNECTION FOR USER: root
<10.53.102.143> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-13699drbw_0_9 `"&& mkdir "` echo /root/.ansible/tmp/ansible-local-13699drbw_0_9/ansible-tmp-1697541963.1307323-13704-90440027433119 `" && echo ansible-tmp-1697541963.1307323-13704-90440027433119="` echo /root/.ansible/tmp/ansible-local-13699drbw_0_9/ansible-tmp-1697541963.1307323-13704-90440027433119 `" ) && sleep 0'
Using module file /root/ansible_release_v103/ansible-junos-stdlib/ansible_collections/juniper/device/plugins/modules/rpc.py
<10.53.102.143> PUT /root/.ansible/tmp/ansible-local-13699drbw_0_9/tmp_7zmvbbr TO /root/.ansible/tmp/ansible-local-13699drbw_0_9/ansible-tmp-1697541963.1307323-13704-90440027433119/AnsiballZ_rpc.py
<10.53.102.143> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-13699drbw_0_9/ansible-tmp-1697541963.1307323-13704-90440027433119/ /root/.ansible/tmp/ansible-local-13699drbw_0_9/ansible-tmp-1697541963.1307323-13704-90440027433119/AnsiballZ_rpc.py && sleep 0'
<10.53.102.143> EXEC /bin/sh -c '/root/ansible_release_v103/venv/bin/python /root/.ansible/tmp/ansible-local-13699drbw_0_9/ansible-tmp-1697541963.1307323-13704-90440027433119/AnsiballZ_rpc.py && sleep 0'
<10.53.102.143> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-13699drbw_0_9/ansible-tmp-1697541963.1307323-13704-90440027433119/ > /dev/null 2>&1 && sleep 0'
ok: [test] => {
    "attrs": {
        "format": "xml",
        "name": "re0"
    },
    "changed": false,
    "format": "xml",
    "invocation": {
        "module_args": {
            "attempts": null,
            "attr": "name=re0",
            "attrs": "name=re0",
            "baud": null,
            "console": null,
            "cs_passwd": null,
            "cs_user": null,
            "dest": null,
            "dest_dir": null,
            "filter": "<configuration><groups><name>re0</name></groups></configuration>",
            "format": "xml",
            "formats": [
                "xml"
            ],
            "host": "10.53.102.143",
            "huge_tree": false,
            "ignore_warning": null,
            "kwargs": null,
            "level": null,
            "logdir": null,
            "logfile": null,
            "mode": null,
            "passwd": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 22,
            "return_output": true,
            "rpc": "get-config",
            "rpcs": [
                "get-config"
            ],
            "ssh_config": null,
            "ssh_private_key_file": null,
            "timeout": 10,
            "user": "root"
        }
    },
    "kwargs": null,
    "msg": "The \"get-config\" RPC executed successfully.",
    "parsed_output": {
        "configuration": {
            "groups": {
                "interfaces": {
                    "interface": {
                        "name": "fxp0",
                        "unit": {
                            "family": {
                                "inet": {
                                    "address": {
                                        "name": "10.53.102.143/19"
                                    }
                                }
                            },
                            "name": "0"
                        }
                    }
                },
                "name": "re0",
                "system": {
                    "backup-router": {
                        "address": "10.53.127.254"
                    },
                    "host-name": "evoeventtestx"
                }
            }
        }
    },
    "rpc": "get-config",
    "stdout": "<configuration changed-seconds=\"1697452040\" changed-localtime=\"2023-10-16 03:27:20 PDT\">\n  <groups>\n    <name>re0</name>\n    <system>\n      <host-name>evoeventtestx</host-name>\n      <backup-router>\n        <address>10.53.127.254</address>\n      </backup-router>\n    </system>\n    <interfaces>\n      <interface>\n        <name>fxp0</name>\n        <unit>\n          <name>0</name>\n          <family>\n            <inet>\n              <address>\n                <name>10.53.102.143/19</name>\n              </address>\n            </inet>\n          </family>\n        </unit>\n      </interface>\n    </interfaces>\n  </groups>\n</configuration>\n",
    "stdout_lines": [
        "<configuration changed-seconds=\"1697452040\" changed-localtime=\"2023-10-16 03:27:20 PDT\">",
        "  <groups>",
        "    <name>re0</name>",
        "    <system>",
        "      <host-name>evoeventtestx</host-name>",
        "      <backup-router>",
        "        <address>10.53.127.254</address>",
        "      </backup-router>",
        "    </system>",
        "    <interfaces>",
        "      <interface>",
        "        <name>fxp0</name>",
        "        <unit>",
        "          <name>0</name>",
        "          <family>",
        "            <inet>",
        "              <address>",
        "                <name>10.53.102.143/19</name>",
        "              </address>",
        "            </inet>",
        "          </family>",
        "        </unit>",
        "      </interface>",
        "    </interfaces>",
        "  </groups>",
        "</configuration>"
    ]
}

TASK [Check TEST 7] *******************************************************************************************************************************************************
task path: /root/ansible_release_v103/ansible-junos-stdlib/tests/pb.juniper_junos_persistent_conn.yml:21
ok: [test] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY RECAP ****************************************************************************************************************************************************************
test                       : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Thanks

chidanandpujar added a commit to chidanandpujar/ansible-junos-stdlib that referenced this issue Oct 17, 2023
chidanandpujar added a commit that referenced this issue Oct 17, 2023
@chidanandpujar
Copy link
Collaborator

Fix is merged via #632

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants