Skip to content

AttributeError: 'JuniperJunosModule' object has no attribute '_pyez_conn' #712

@JordanAtherton

Description

@JordanAtherton
- Bug Report
Module Name
juniper.device.file_copy
juniper.device collection and Python libraries version:

Collection                               Version
---------------------------------------- -------
juniper.device                           1.0.7  

junipernetworks.junos                    9.1.0

ansible [core 2.18.1]

ansible==11.1.0
ansible-core==2.18.1
junos-eznc==2.7.2

OS / Environment

Version: JUNOS 21.4R3-S9.5
Model: RE-EX4400-48T
Summary
Im trying utilize the juniper.device collection, juniper.device.file_copy to push files to our juniper devices.
I even did a fresh install in a Virtualized contained on my Mac, (where I am testing now) to verify if it will work on a fresh install of ansible. No matter what I try I can not get it to work. I have created an test connection playbook and that seems to connect just fine, when using this collection I seem to have issues.

Steps to reproduce
------
On a fresh install of ansible, with junos-eznc installed, I created this playbook:

- name: Testing Connection
  hosts: test
  gather_facts: no
  connection: local
  
  tasks:
    - name: Collect Juniper Information
      junipernetworks.junos.junos_command:
        commands:
          - "show chassis hardware detail"


TASK [Collect Juniper Information] ***********************************************************************************************************************************************************************************
ok: [JuniperCopperSwitch]

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

This is the playbook just testing this collection:

---
- name: Copy script to the Junos device
  hosts: test
  connection: local
  gather_facts: false

  tasks:
    - name: Copy a local script to the Junos device
      juniper.device.file_copy:
        action: put
        file: testing.txt
        local_dir: /Users/jordan/VirtualEnvironment/Ansible/NewTower/playbooks/
        remote_dir: /var/tmp/
and i get this:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'JuniperJunosModule' object has no attribute '_pyez_conn'
fatal: [JuniperCopperSwitch]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/Users/jordan/.ansible/tmp/ansible-local-16271_wbc1yrp/ansible-tmp-1736311762.7297258-16273-89005574192951/AnsiballZ_file_copy.py\", line 107, in <module>\n    _ansiballz_main()\n    ~~~~~~~~~~~~~~~^^\n  File \"/Users/jordan/.ansible/tmp/ansible-local-16271_wbc1yrp/ansible-tmp-1736311762.7297258-16273-89005574192951/AnsiballZ_file_copy.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/jordan/.ansible/tmp/ansible-local-16271_wbc1yrp/ansible-tmp-1736311762.7297258-16273-89005574192951/AnsiballZ_file_copy.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.file_copy', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.file_copy', _modlib_path=modlib_path),\n    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n                     run_name='__main__', alter_sys=True)\n                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_0dhbolms/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/modules/file_copy.py\", line 158, in <module>\n  File \"/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_0dhbolms/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/modules/file_copy.py\", line 121, in main\n  File \"/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_0dhbolms/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 668, in __init__\n  File \"/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_0dhbolms/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 803, in fail_json\n  File \"/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_0dhbolms/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1287, in close_configuration\nAttributeError: 'JuniperJunosModule' object has no attribute '_pyez_conn'\n", "module_stdout": "", "msg": "MODULE FAILURE: No start of json char found\nSee stdout/stderr for the exact error", "rc": 1}

JuniperCopperSwitch            : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Expected results

Im just testing the collection to send a test.txt file with some a word that says test just to make sure i can push software directly to devices.

Actual results

redirecting (type: connection) ansible.builtin.netconf to ansible.netcommon.netconf
redirecting (type: netconf) ansible.builtin.junos to junipernetworks.junos.junos
<10.255.151.19> ESTABLISH LOCAL CONNECTION FOR USER: jordan
<10.255.151.19> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l `"&& mkdir "` echo /Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732 `" && echo ansible-tmp-1736312127.9306371-16531-151763372786732="` echo /Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732 `" ) && sleep 0'
Using module file /Users/jordan/VirtualEnvironment/Ansible/NewTower/.ansible/collections/ansible_collections/juniper/device/plugins/modules/file_copy.py
<10.255.151.19> PUT /Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/tmpxb5n_12_ TO /Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732/AnsiballZ_file_copy.py
<10.255.151.19> EXEC /bin/sh -c 'chmod u+x /Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732/ /Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732/AnsiballZ_file_copy.py && sleep 0'
<10.255.151.19> EXEC /bin/sh -c '/Users/jordan/VirtualEnvironment/Ansible/bin/python3.13 /Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732/AnsiballZ_file_copy.py && sleep 0'
<10.255.151.19> EXEC /bin/sh -c 'rm -f -r /Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732/AnsiballZ_file_copy.py", line 107, in <module>
    _ansiballz_main()
    ~~~~~~~~~~~~~~~^^
  File "/Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732/AnsiballZ_file_copy.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732/AnsiballZ_file_copy.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.file_copy', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.file_copy', _modlib_path=modlib_path),
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     run_name='__main__', alter_sys=True)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_ajzydhk3/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/modules/file_copy.py", line 158, in <module>
  File "/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_ajzydhk3/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/modules/file_copy.py", line 121, in main
  File "/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_ajzydhk3/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py", line 668, in __init__
  File "/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_ajzydhk3/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py", line 803, in fail_json
  File "/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_ajzydhk3/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py", line 1287, in close_configuration
AttributeError: 'JuniperJunosModule' object has no attribute '_pyez_conn'
fatal: [JuniperCopperSwitch]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732/AnsiballZ_file_copy.py\", line 107, in <module>\n    _ansiballz_main()\n    ~~~~~~~~~~~~~~~^^\n  File \"/Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732/AnsiballZ_file_copy.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/jordan/.ansible/tmp/ansible-local-16529v693kg6l/ansible-tmp-1736312127.9306371-16531-151763372786732/AnsiballZ_file_copy.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.file_copy', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.file_copy', _modlib_path=modlib_path),\n    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n                     run_name='__main__', alter_sys=True)\n                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_ajzydhk3/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/modules/file_copy.py\", line 158, in <module>\n  File \"/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_ajzydhk3/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/modules/file_copy.py\", line 121, in main\n  File \"/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_ajzydhk3/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 668, in __init__\n  File \"/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_ajzydhk3/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 803, in fail_json\n  File \"/var/folders/lt/6151215d6sv21zjr358z80kr0000gr/T/ansible_juniper.device.file_copy_payload_ajzydhk3/ansible_juniper.device.file_copy_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1287, in close_configuration\nAttributeError: 'JuniperJunosModule' object has no attribute '_pyez_conn'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE: No start of json char found\nSee stdout/stderr for the exact error",
    "rc": 1
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions