Skip to content

juniper.device.config fails with juniper.device.pyez connection #580

@Arvid-VF

Description

@Arvid-VF

Issue Type

  • Bug Report

Module Name

juniper.device.config

juniper.device collection and Python libraries version

ansible [core 2.12.1]
  config file = /home/user/repos/access-switches/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /environments/venv_ansible/lib64/python3.8/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /environments/venv_ansible/bin/ansible
  python version = 3.8.11 (default, Jul 23 2021, 14:55:16) [GCC 9.1.1 20190605 (Red Hat 9.1.1-2)]
  jinja version = 3.0.3
  libyaml = True

ansible==5.0.1
ansible-core==2.12.1
bcrypt==3.2.0
cffi==1.15.0
colorama==0.4.4
configparser==5.2.0
cryptography==36.0.1
future==0.18.2
icdiff==2.0.4
Jinja2==3.0.3
jsnapy==1.3.6
junos-eznc==2.6.3
jxmlease==1.0.3
lxml==4.7.1
MarkupSafe==2.0.1
ncclient==0.6.9
netaddr==0.8.0
packaging==21.3
paramiko==2.8.1
pycparser==2.21
PyNaCl==1.4.0
pyparsing==3.0.6
pyserial==3.5
PyYAML==6.0
resolvelib==0.5.4
scp==0.14.2
six==1.16.0
transitions==0.8.10
xmltodict==0.12.0
yamlordereddictloader==0.4.0

Collection     Version
-------------- -------
juniper.device 1.0.1 

OS / Environment

JUNOS 18.2R3-S4.1 EX2300C

Summary

Running juniper.device.config with juniper.device.pyez as connection type results in below error.
connection: local works as expected.

Steps to reproduce

Run juniper.device.config with juniper.device.pyez as connection type.

- name: Push set commands, commit, and confirm
  hosts: all
  serial: 5
  strategy: free
  collections:
    - juniper.device
  connection: juniper.device.pyez
  gather_facts: no

  vars_prompt:
    - name: zon
      prompt: Zone to configure (zone or zone)
      private: no

    - name: username
      prompt: Junos Username
      private: no

    - name: password
      prompt: Junos Password
      private: yes

  vars:
    user: "{{ username }}"
    passwd: "{{ password }}"
    port: "22"
    timeout: 60

  tasks:
    - name: Check Netconf connectivity
      ansible.builtin.wait_for:
        host: "{{ ansible_host }}"
        port: 22
        timeout: 5
      check_mode: no

    - name: Push config and commit
      juniper.device.config:
        src: "inventory/{{ zon }}/config/{{ inventory_hostname }}.conf"
        load: update
        check: yes
        diff: yes
        commit: yes
        ignore_warning: no
        confirmed: 10
        comment: "Commited by ansible"
      register: response

Below playbook with juniper.device.command works as expected.

- name: Get uptime on switch
  hosts: all
  strategy: free
  serial: 10
  collections:
    - juniper.device
  connection: juniper.device.pyez
  gather_facts: no

  vars_prompt:
    - name: username
      prompt: Junos Username
      private: no

    - name: password
      prompt: Junos Password
      private: yes

  vars:
    user: "{{ username }}"
    passwd: "{{ password }}"
    port: "22"
    timeout: 60

  tasks:
    - name: Get uptime
      juniper.device.command:
        commands: "show system uptime"
      register: response

    - name: Print response
      ansible.builtin.debug:
        var: response

Expected results

Same result as with connection: local

Actual results

Output is sanitized. Nothing removed only replaced.

ansible-playbook [core 2.12.1]
  config file = /home/user/repos/access-switches/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /environments/venv_ansible/lib64/python3.8/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /environments/venv_ansible/bin/ansible-playbook
  python version = 3.8.11 (default, Jul 23 2021, 14:55:16) [GCC 9.1.1 20190605 (Red Hat 9.1.1-2)]
  jinja version = 3.0.3
  libyaml = True
Using /home/user/repos/access-switches/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /home/user/repos/access-switches/inventory/zone/hosts.ini as it did not pass its verify_file() method
script declined parsing /home/user/repos/access-switches/inventory/zone/hosts.ini as it did not pass its verify_file() method
auto declined parsing /home/user/repos/access-switches/inventory/zone/hosts.ini as it did not pass its verify_file() method
yaml declined parsing /home/user/repos/access-switches/inventory/zone/hosts.ini as it did not pass its verify_file() method
Not replacing invalid character(s) "{'-'}" in group name (EX2200-24)
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
Not replacing invalid character(s) "{'-'}" in group name (EX2200-24)
Not replacing invalid character(s) "{'-'}" in group name (EX2200-48)
Not replacing invalid character(s) "{'-'}" in group name (EX2200-48)
Not replacing invalid character(s) "{'-'}" in group name (EX3300-48)
Not replacing invalid character(s) "{'-'}" in group name (EX3300-48)
Not replacing invalid character(s) "{'-'}" in group name (EX2300-48)
Not replacing invalid character(s) "{'-'}" in group name (EX2300-48)
Parsed /home/user/repos/access-switches/inventory/zone/hosts.ini inventory source with ini plugin
Loading collection juniper.device from /home/user/.ansible/collections/ansible_collections/juniper/device
Loading callback plugin default of type stdout, v2.0 from /environments/venv_ansible/lib64/python3.8/site-packages/ansible/plugins/callback/default.py
[WARNING]: Skipping callback plugin 'jsnapy', unable to load
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.push.config.yml ***********************************************************************************************************************************************************************************************************************************
Positional arguments: pb.push.config.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
check: True
inventory: ('/home/user/repos/access-switches/inventory/zone/hosts.ini',)
subset: junos-switch-ex2300
forks: 5
1 plays in pb.push.config.yml
zone to configure (zone or zone): zone
Junos Username: user
Junos Password:
[WARNING]: Found variable using reserved name: port
[WARNING]: Found variable using reserved name: timeout

PLAY [Push set commands, commit, and confirm] ******************************************************************************************************************************************************************************************************************
META: ran handlers
Loading collection ansible.netcommon from /environments/venv_ansible/lib64/python3.8/site-packages/ansible_collections/ansible/netcommon
<xx.xx.xx.xx> attempting to start connection
<xx.xx.xx.xx> using connection plugin juniper.device.pyez
Found ansible-connection at path /environments/venv_ansible/bin/ansible-connection
<xx.xx.xx.xx> local domain socket does not exist, starting it
<xx.xx.xx.xx> control socket path is /home/user/.ansible/pc/f1bf7e216c
<xx.xx.xx.xx> Loading collection juniper.device from /home/user/.ansible/collections/ansible_collections/juniper/device
<xx.xx.xx.xx> Loading collection ansible.netcommon from /environments/venv_ansible/lib64/python3.8/site-packages/ansible_collections/ansible/netcommon
<xx.xx.xx.xx> local domain socket listeners started successfully
<xx.xx.xx.xx> 
<xx.xx.xx.xx> local domain socket path is /home/user/.ansible/pc/f1bf7e216c
<xx.xx.xx.xx> ESTABLISH LOCAL CONNECTION FOR USER: user
<xx.xx.xx.xx> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/user/.ansible/tmp/ansible-local-22411i_trsu63 `"&& mkdir "` echo /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257185.2115843-22416-62482046041685 `" && echo ansible-tmp-1640257185.2115843-22416-62482046041685="` echo /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257185.2115843-22416-62482046041685 `" ) && sleep 0'
Using module file /environments/venv_ansible/lib64/python3.8/site-packages/ansible/modules/wait_for.py
<xx.xx.xx.xx> PUT /home/user/.ansible/tmp/ansible-local-22411i_trsu63/tmp_r0ul_xb TO /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257185.2115843-22416-62482046041685/AnsiballZ_wait_for.py
<xx.xx.xx.xx> EXEC /bin/sh -c 'chmod u+x /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257185.2115843-22416-62482046041685/ /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257185.2115843-22416-62482046041685/AnsiballZ_wait_for.py && sleep 0'
<xx.xx.xx.xx> EXEC /bin/sh -c '/environments/venv_ansible/bin/python3 /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257185.2115843-22416-62482046041685/AnsiballZ_wait_for.py && sleep 0'
<xx.xx.xx.xx> EXEC /bin/sh -c 'rm -f -r /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257185.2115843-22416-62482046041685/ > /dev/null 2>&1 && sleep 0'

TASK [Check Netconf connectivity] ******************************************************************************************************************************************************************************************************************************
task path: /home/user/repos/access-switches/pb.push.config.yml:32
ok: [junos-switch-ex2300] => {
    "changed": false,
    "elapsed": 0,
    "invocation": {
        "module_args": {
            "active_connection_states": [
                "ESTABLISHED",
                "FIN_WAIT1",
                "FIN_WAIT2",
                "SYN_RECV",
                "SYN_SENT",
                "TIME_WAIT"
            ],
            "connect_timeout": 5,
            "delay": 0,
            "exclude_hosts": null,
            "host": "xx.xx.xx.xx",
            "msg": null,
            "path": null,
            "port": 22,
            "search_regex": null,
            "sleep": 1,
            "state": "started",
            "timeout": 5
        }
    },
    "match_groupdict": {},
    "match_groups": [],
    "path": null,
    "port": 22,
    "search_regex": null,
    "state": "started"
}
Loading collection ansible.netcommon from /environments/venv_ansible/lib64/python3.8/site-packages/ansible_collections/ansible/netcommon
<xx.xx.xx.xx> attempting to start connection
<xx.xx.xx.xx> using connection plugin juniper.device.pyez
Found ansible-connection at path /environments/venv_ansible/bin/ansible-connection
<xx.xx.xx.xx> found existing local domain socket, using it!
<xx.xx.xx.xx> 
<xx.xx.xx.xx> local domain socket path is /home/user/.ansible/pc/f1bf7e216c
<xx.xx.xx.xx> ESTABLISH LOCAL CONNECTION FOR USER: user
<xx.xx.xx.xx> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/user/.ansible/tmp/ansible-local-22411i_trsu63 `"&& mkdir "` echo /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874 `" && echo ansible-tmp-1640257186.1760092-22441-208977939636874="` echo /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874 `" ) && sleep 0'
Using module file /home/user/.ansible/collections/ansible_collections/juniper/device/plugins/modules/config.py
<xx.xx.xx.xx> PUT /home/user/.ansible/tmp/ansible-local-22411i_trsu63/tmps4jxl18e TO /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874/AnsiballZ_config.py
<xx.xx.xx.xx> EXEC /bin/sh -c 'chmod u+x /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874/ /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874/AnsiballZ_config.py && sleep 0'
<xx.xx.xx.xx> EXEC /bin/sh -c '/environments/venv_ansible/bin/python3 /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874/AnsiballZ_config.py && sleep 0'
<xx.xx.xx.xx> EXEC /bin/sh -c 'rm -f -r /home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874/ > /dev/null 2>&1 && sleep 0'

TASK [Push config and commit] **********************************************************************************************************************************************************************************************************************************
task path: /home/user/repos/access-switches/pb.push.config.yml:39
The full traceback is:
Traceback (most recent call last):
  File "/home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874/AnsiballZ_config.py", line 107, in <module>
    _ansiballz_main()
  File "/home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874/AnsiballZ_config.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874/AnsiballZ_config.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.config', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.config', _modlib_path=modlib_path),
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/runpy.py", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_juniper.device.config_payload_zk0asrs_/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py", line 1164, in <module>
  File "/tmp/ansible_juniper.device.config_payload_zk0asrs_/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py", line 1055, in main
  File "/tmp/ansible_juniper.device.config_payload_zk0asrs_/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py", line 1460, in load_configuration
  File "/tmp/ansible_juniper.device.config_payload_zk0asrs_/ansible_juniper.device.config_payload.zip/ansible/module_utils/connection.py", line 200, in __rpc__
ansible.module_utils.connection.ConnectionError: 'Connection' object has no attribute 'pyez_exception'
fatal: [junos-switch-ex2300]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874/AnsiballZ_config.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874/AnsiballZ_config.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/user/.ansible/tmp/ansible-local-22411i_trsu63/ansible-tmp-1640257186.1760092-22441-208977939636874/AnsiballZ_config.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.config', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.config', _modlib_path=modlib_path),\n  File \"/opt/rh/rh-python38/root/usr/lib64/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/opt/rh/rh-python38/root/usr/lib64/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/opt/rh/rh-python38/root/usr/lib64/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_juniper.device.config_payload_zk0asrs_/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1164, in <module>\n  File \"/tmp/ansible_juniper.device.config_payload_zk0asrs_/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1055, in main\n  File \"/tmp/ansible_juniper.device.config_payload_zk0asrs_/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1460, in load_configuration\n  File \"/tmp/ansible_juniper.device.config_payload_zk0asrs_/ansible_juniper.device.config_payload.zip/ansible/module_utils/connection.py\", line 200, in __rpc__\nansible.module_utils.connection.ConnectionError: 'Connection' object has no attribute 'pyez_exception'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP *****************************************************************************************************************************************************************************************************************************************************
junos-switch-ex2300   : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions