Juniper / ansible-junos-stdlib

Junos modules for Ansible
Apache License 2.0
307 stars 158 forks source link

Unable to run juniper.device.config with a template in combination with juniper.device.pyez connection #565

Closed 33Fraise33 closed 9 months ago

33Fraise33 commented 3 years ago

Issue Type

Module Name

juniper.device.config

juniper.device collection and Python libraries version

ansible [core 2.11.4]
  config file = /home/gianni/git/5g-ansible-networking/ansible.cfg
  configured module search path = ['/home/gianni/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/gianni/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.6 (default, Jun 30 2021, 10:22:16) [GCC 11.1.0]
  jinja version = 2.11.3
  libyaml = True

aiofiles @ file:///build/python-aiofiles/src/aiofiles/dist/aiofiles-0.7.0-py3-none-any.whl
aiohttp==3.7.4.post0
aiohttp-cors==0.7.0
ansible==4.4.0
ansible-core==2.11.4
apparmor==3.0.3
appdirs==1.4.4
application-utility==1.3.2
async-generator==1.10
async-timeout==3.0.1
attrs==21.2.0
Babel==2.9.1
bcrypt==3.2.0
bidict==0.21.2
Brlapi==0.8.2
btrfsutil==5.13.1
CacheControl==0.12.6
ceph==1.0.0
ceph-volume==1.0.0
cephfs==2.0.0
cephfs-shell==0.0.1
certifi==2020.12.5
cffi==1.14.5
chardet==3.0.4
click==7.1.2
cmd2==1.5.0
colorama==0.4.4
construct==2.10.67
contextlib2==0.6.0.post1
cryptography==3.4.4
cupshelpers==1.0
decorator==5.0.9
distlib==0.3.2
distro==1.5.0
dnspython==1.16.0
docker==4.4.1
docopt==0.6.2
entrypoints==0.3
evdev==1.4.0
filelock==3.0.12
flake8==3.9.2
future==0.18.2
Glances==3.2.1
gns3-gui==2.2.23
gns3-server==2.2.23
gsm0338==1.0.0
html5lib==1.1
idna==3.1
importlib-metadata==4.6.1
isc==2.0
isodate==0.6.0
Jinja2==2.11.3
jsonpath-ng==1.5.2
jsonschema==3.2.0
junos-eznc==2.6.2
jxmlease==1.0.3
keyutils==0.6
lensfun==0.3.95
LibAppArmor==3.0.3
libfdt==1.6.1
libtorrent===1.2.14-build-libtorrent-rasterbar-src-libtorrent-rasterbar-1.2.14-bindings-python
libvirt-python==7.3.0
louis==3.18.0
lxml==4.6.3
Markdown==3.3.4
MarkupSafe==1.1.1
mccabe==0.6.1
meson==0.59.1
more-itertools==8.8.0
msgpack==1.0.2
multidict==4.7.6
ncclient==0.6.9
netaddr==0.8.0
netsnmp-python==1.0a1
npyscreen==4.10.5
ordered-set==4.0.2
packaging==20.8
pacman-mirrors==4.21.5
paramiko==2.7.2
pep517==0.11.0
Pillow==8.3.1
ply==3.11
progress==1.5
prompt-toolkit==3.0.20
protobuf==3.6.0
psutil==5.8.0
py-cpuinfo==8.0.0
pycairo==1.20.0
pycodestyle==2.7.0
pycountry==20.7.3
pycparser==2.20
pycryptodome==3.10.1
pycups==2.0.1
pycurl==7.43.0.6
pyflakes==2.3.1
Pygments==2.10.0
PyGObject==3.40.1
PyNaCl==1.4.0
pynetbox==5.3.0
pyOpenSSL==20.0.1
pyparsing==2.4.7
pyperclip==1.7.0
PyQt5==5.15.4
PyQt5-sip==12.9.0
pyrsistent==0.18.0
pyscard==2.0.1
pyserial==3.5
pySim==1.0
pysmbc==1.0.23
PySocks==1.7.1
python-dotenv==0.15.0
pytlv==0.71
pytz==2021.1
PyYAML==5.4.1
rados==2.0.0
rbd==2.0.0
reportlab==3.5.68
requests==2.26.0
resolvelib==0.5.5
retrying==1.3.3
rgw==2.0.0
scp==0.13.6
sentry-sdk==1.3.1
sip==4.19.25
six==1.11.0
speedtest-cli==2.1.3
streamlink==2.3.0
team==1.0
toml==0.10.2
tomli==1.2.1
transitions==0.8.8
typing-extensions==3.7.4.3
udiskie==2.3.3
ultrasync==0.9.2
urllib3==1.26.2
virtualenv==20.4.2
wcwidth==0.2.5
webencodings==0.5.1
websocket-client==0.59.0
xmltodict==0.12.0
yamlordereddictloader==0.4.0
yarl==1.4.2
youtube-dl==2021.6.6
zipp==3.5.0

# /home/gianni/.ansible/collections/ansible_collections
Collection     Version
-------------- -------
juniper.device 1.0.0

OS / Environment

Juniper EX3400 JUNOS 20.4R2-S1.6

Summary

Running juniper.device.config with a template does not work with juniper.device.pyez as connection type.

Steps to reproduce

change connection type from ansible_connection: local to ansible_connection: juniper.device.pyez

- name: USER - user settings for Juniper
  juniper.device.config:
    load: merge
    template: "{{ role_path }}/templates/junos_users.conf.j2"
    format: text
    config_mode: private
    timeout: 20
    vars:
      admin_users: "{{ admin_users }}"
  when: "'juniper' in group_names"

Expected results

TASK [common : USER - user settings for Juniper] **********************************************
ok: [PR_BAC_SW03]
ok: [PR_BAC_SW04]

Actual results

TASK [common : USER - user settings for Juniper] **********************************************
task path: /home/gianni/git/5g-ansible-networking/roles/common/tasks/05-users.yml:31
Trying secret <ansible.parsing.vault.PromptVaultSecret object at 0x7f82cd4bf4f0> for vault_id=default
Trying secret <ansible.parsing.vault.PromptVaultSecret object at 0x7f82cd4bf4f0> for vault_id=default
Trying secret <ansible.parsing.vault.PromptVaultSecret object at 0x7f82cd4bf4f0> for vault_id=default
File lookup using /home/gianni/git/5g-ansible-networking/roles/common/files/keys/OPS-IT/SaelensFrederic.pub as file
File lookup using /home/gianni/git/5g-ansible-networking/roles/common/files/keys/OPS-IT/StubbeGianni.pub as file
File lookup using /home/gianni/git/5g-ansible-networking/roles/common/files/keys/OPS-IT/PirletTom.pub as file
Trying secret <ansible.parsing.vault.PromptVaultSecret object at 0x7f82cd4bf4f0> for vault_id=default
File lookup using /home/gianni/git/5g-ansible-networking/roles/common/files/keys/OPS-IT/DoutrepontJonathan.pub as file
File lookup using /home/gianni/git/5g-ansible-networking/roles/common/files/keys/OPS-IT/HollebekeYentel.pub as file
File lookup using /home/gianni/git/5g-ansible-networking/roles/common/files/keys/OPS-IT/SaelensFrederic.pub as file
File lookup using /home/gianni/git/5g-ansible-networking/roles/common/files/keys/OPS-IT/StubbeGianni.pub as file
File lookup using /home/gianni/git/5g-ansible-networking/roles/common/files/keys/OPS-IT/PirletTom.pub as file
File lookup using /home/gianni/git/5g-ansible-networking/roles/common/files/keys/OPS-IT/DoutrepontJonathan.pub as file
File lookup using /home/gianni/git/5g-ansible-networking/roles/common/files/keys/OPS-IT/HollebekeYentel.pub as file
Loading collection ansible.netcommon from /home/gianni/.ansible/collections/ansible_collections/ansible/netcommon
<10.210.0.4> attempting to start connection
<10.210.0.4> using connection plugin juniper.device.pyez
Found ansible-connection at path /usr/bin/ansible-connection
Loading collection ansible.netcommon from /home/gianni/.ansible/collections/ansible_collections/ansible/netcommon
<10.210.0.5> attempting to start connection
<10.210.0.5> using connection plugin juniper.device.pyez
Found ansible-connection at path /usr/bin/ansible-connection
<10.210.0.4> local domain socket does not exist, starting it
<10.210.0.4> control socket path is /home/gianni/.ansible/pc/9548e76d50
<10.210.0.4> Loading collection juniper.device from /home/gianni/.ansible/collections/ansible_collections/juniper/device
<10.210.0.4> Loading collection ansible.netcommon from /home/gianni/.ansible/collections/ansible_collections/ansible/netcommon
<10.210.0.4> Trying secret <ansible.parsing.vault.PromptVaultSecret object at 0x7f3ad5270310> for vault_id=default
<10.210.0.4> local domain socket listeners started successfully
<10.210.0.4>
<10.210.0.4> local domain socket path is /home/gianni/.ansible/pc/9548e76d50
Trying secret <ansible.parsing.vault.PromptVaultSecret object at 0x7f82cd4bf4f0> for vault_id=default
<10.210.0.4> ESTABLISH LOCAL CONNECTION FOR USER: gianni
<10.210.0.4> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/gianni/.ansible/tmp/ansible-local-42984230swsb2 `"&& mkdir "` echo /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467 `" && echo ansible-tmp-1630328943.1062696-43098-33757188266467="` echo /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467 `" ) && sleep 0'
<10.210.0.5> local domain socket does not exist, starting it
<10.210.0.5> control socket path is /home/gianni/.ansible/pc/d4adb77aba
<10.210.0.5> Loading collection juniper.device from /home/gianni/.ansible/collections/ansible_collections/juniper/device
<10.210.0.5> Loading collection ansible.netcommon from /home/gianni/.ansible/collections/ansible_collections/ansible/netcommon
<10.210.0.5> Trying secret <ansible.parsing.vault.PromptVaultSecret object at 0x7fef7b3e4310> for vault_id=default
<10.210.0.5> local domain socket listeners started successfully
<10.210.0.5>
<10.210.0.5> local domain socket path is /home/gianni/.ansible/pc/d4adb77aba
Trying secret <ansible.parsing.vault.PromptVaultSecret object at 0x7f82cd4bf4f0> for vault_id=default
<10.210.0.5> ESTABLISH LOCAL CONNECTION FOR USER: gianni
<10.210.0.5> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/gianni/.ansible/tmp/ansible-local-42984230swsb2 `"&& mkdir "` echo /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954 `" && echo ansible-tmp-1630328943.1938274-43099-265171896648954="` echo /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954 `" ) && sleep 0'
Using module file /home/gianni/.ansible/collections/ansible_collections/juniper/device/plugins/modules/config.py
<10.210.0.4> PUT /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/tmppit3su8t TO /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467/AnsiballZ_config.py
Using module file /home/gianni/.ansible/collections/ansible_collections/juniper/device/plugins/modules/config.py
<10.210.0.4> EXEC /bin/sh -c 'chmod u+x /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467/ /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467/AnsiballZ_config.py && sleep 0'
<10.210.0.5> PUT /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/tmpzi39cuyd TO /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954/AnsiballZ_config.py
<10.210.0.5> EXEC /bin/sh -c 'chmod u+x /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954/ /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954/AnsiballZ_config.py && sleep 0'
<10.210.0.4> EXEC /bin/sh -c '/usr/bin/python /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467/AnsiballZ_config.py && sleep 0'
<10.210.0.5> EXEC /bin/sh -c '/usr/bin/python /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954/AnsiballZ_config.py && sleep 0'
<10.210.0.4> EXEC /bin/sh -c 'rm -f -r /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467/ > /dev/null 2>&1 && sleep 0'
<10.210.0.5> EXEC /bin/sh -c 'rm -f -r /home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467/AnsiballZ_config.py", line 100, in <module>
    _ansiballz_main()
  File "/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467/AnsiballZ_config.py", line 92, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467/AnsiballZ_config.py", line 40, 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 "/usr/lib/python3.9/runpy.py", line 210, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_juniper.device.config_payload_y1c78bv9/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_y1c78bv9/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py", line 1066, in main
  File "/tmp/ansible_juniper.device.config_payload_y1c78bv9/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py", line 1452, in load_configuration
  File "/tmp/ansible_juniper.device.config_payload_y1c78bv9/ansible_juniper.device.config_payload.zip/ansible/module_utils/connection.py", line 195, in __rpc__
ansible.module_utils.connection.ConnectionError: 'Connection' object has no attribute 'pyez_exception'
fatal: [PR_BAC_SW03]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467/AnsiballZ_config.py\", line 100, in <module>\n    _ansiballz_main()\n  File \"/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467/AnsiballZ_config.py\", line 92, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1062696-43098-33757188266467/AnsiballZ_config.py\", line 40, 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 \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_juniper.device.config_payload_y1c78bv9/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_y1c78bv9/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1066, in main\n  File \"/tmp/ansible_juniper.device.config_payload_y1c78bv9/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1452, in load_configuration\n  File \"/tmp/ansible_juniper.device.config_payload_y1c78bv9/ansible_juniper.device.config_payload.zip/ansible/module_utils/connection.py\", line 195, 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
}
The full traceback is:
Traceback (most recent call last):
  File "/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954/AnsiballZ_config.py", line 100, in <module>
    _ansiballz_main()
  File "/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954/AnsiballZ_config.py", line 92, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954/AnsiballZ_config.py", line 40, 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 "/usr/lib/python3.9/runpy.py", line 210, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_juniper.device.config_payload_82h0pkli/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_82h0pkli/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py", line 1066, in main
  File "/tmp/ansible_juniper.device.config_payload_82h0pkli/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py", line 1452, in load_configuration
  File "/tmp/ansible_juniper.device.config_payload_82h0pkli/ansible_juniper.device.config_payload.zip/ansible/module_utils/connection.py", line 195, in __rpc__
ansible.module_utils.connection.ConnectionError: 'Connection' object has no attribute 'pyez_exception'
fatal: [PR_BAC_SW04]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954/AnsiballZ_config.py\", line 100, in <module>\n    _ansiballz_main()\n  File \"/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954/AnsiballZ_config.py\", line 92, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/gianni/.ansible/tmp/ansible-local-42984230swsb2/ansible-tmp-1630328943.1938274-43099-265171896648954/AnsiballZ_config.py\", line 40, 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 \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_juniper.device.config_payload_82h0pkli/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_82h0pkli/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1066, in main\n  File \"/tmp/ansible_juniper.device.config_payload_82h0pkli/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1452, in load_configuration\n  File \"/tmp/ansible_juniper.device.config_payload_82h0pkli/ansible_juniper.device.config_payload.zip/ansible/module_utils/connection.py\", line 195, 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
}
ntwrknrd commented 2 years ago

@33Fraise33 Did you ever find a way around this? Seeing a similar issue when applying a 'set' config to vMXs:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.module_utils.connection.ConnectionError: 'Connection' object has no attribute 'pyez_exception'
fatal: [clab-netjob-pvc-vmx1]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/netdev/.ansible/tmp/ansible-local-892gpk0v_q/ansible-tmp-1647402243.6921282-517-106646245873870/AnsiballZ_config.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/netdev/.ansible/tmp/ansible-local-892gpk0v_q/ansible-tmp-1647402243.6921
282-517-106646245873870/AnsiballZ_config.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/netdev/.ansible/tmp/ansible-local-892gpk0v_q/ansible-tmp-1647402243.6921282-517-106646245873870/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 \"/home/netdev/.pyenv/versions/3.9.10/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/home/netdev/.pyenv/versions/3.9.10/lib/python3.9/runpy.py\", line 97, in _run_module_code\n
_run_code(code, mod_globals, init_globals,\n  File \"/home/netdev/.pyenv/versions/3.9.10/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_juniper.device.config_payload_lev29f3d/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1164, in <module>\n  File \"/tmp/ansible_juni
per.device.config_payload_lev29f3d/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_lev29f3d/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_lev29f3d/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}
daniel-zook commented 2 years ago

Same thing happens when using src with a .conf file:

fatal: [192.168.30.102]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/root/.ansible/tmp/ansible-local-171962pta30sr/ansible-tmp-1647957357.5491126-17236-261819195196873/AnsiballZ_config.py\", line 102, in \n _ansiballz_main()\n File \"/root/.ansible/tmp/ansible-local-171962pta30sr/ansible-tmp-1647957357.5491126-17236-261819195196873/AnsiballZ_config.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/root/.ansible/tmp/ansible-local-171962pta30sr/ansible-tmp-1647957357.5491126-17236-261819195196873/AnsiballZ_config.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.config', init_globals=None, run_name='main', alter_sys=True)\n File \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_config_payload_t5bh08gd/ansible_config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1164, in \n File \"/tmp/ansible_config_payload_t5bh08gd/ansible_config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1055, in main\n File \"/tmp/ansible_config_payload_t5bh08gd/ansible_config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1460, in load_configuration\n File \"/tmp/ansible_config_payload_t5bh08gd/ansible_config_payload.zip/ansible/module_utils/connection.py\", line 195, 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}

wdst-gcet commented 2 years ago

Yeah same thing is happening to me as well using ansible_connection: juniper.device.pyez. When I run ansible_connection: local it works

Task

- name: junos apply system configuration
  juniper.device.config:
    timeout: 50
    load: "replace"
    src: "{{config_dir}}/{{inventory_hostname}}_system.conf"
    diff: true
    commit: true
    comment: "ansible playbook {{ ansible_play_name }}, commit confirm for role {{ role_name }}"
    confirm: 5
  register: config_result

Results using juniper.device.pyez

fatal: [192.168.88.10]: FAILED! => {
    "changed": false,
    "module_stderr": "\nTraceback (most recent call last):\n  File \"/Users/user/.ansible/tmp/ansible-local-68239nifa3uql/ansible-tmp-1656544277.101295-68272-125179708915826/AnsiballZ_config.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/Users/user/.ansible/tmp/ansible-local-68239nifa3uql/ansible-tmp-1656544277.101295-68272-125179708915826/AnsiballZ_config.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/user/.ansible/tmp/ansible-local-68239nifa3uql/ansible-tmp-1656544277.101295-68272-125179708915826/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 \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 209, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/xq/cv8fbfhn6f100mmlykk16jmh0000gn/T/ansible_juniper.device.config_payload_bkoorqji/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1164, in <module>\n  File \"/var/folders/xq/cv8fbfhn6f100mmlykk16jmh0000gn/T/ansible_juniper.device.config_payload_bkoorqji/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1055, in main\n  File \"/var/folders/xq/cv8fbfhn6f100mmlykk16jmh0000gn/T/ansible_juniper.device.config_payload_bkoorqji/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1460, in load_configuration\n  File \"/var/folders/xq/cv8fbfhn6f100mmlykk16jmh0000gn/T/ansible_juniper.device.config_payload_bkoorqji/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
}
wdst-gcet commented 2 years ago

I spent a few more hours today trying to debug and find a solution that allows the use of connection: juniper.device.pyez. Sadly I don’t have much time to work on this but I figured my work around may help others.

Workaround

Import the juniper.junos roles and use the juniper_junos_config role to perform tasks that require applying configuration. The juniper.device.config collection works for retrieving configurations and other juniper tasks we require. So in short…

Play & Task Example

- name: 'Juniper apply config workaround for ISSUE https://github.com/Juniper/ansible-junos-stdlib/issues/565'
  hosts: juniper
  connection: juniper.device.pyez
  gather_facts: false

  roles:
    - juniper.junos

  vars:
    config_dir: "{{playbook_dir}}/tmp"

  tasks:
    # Retrieving config with (collection) juniper.device.config (WORKING)
    - name: retrieve config with (collection) juniper.device.config (WORKING)
      juniper.device.config:
        retrieve: 'committed'
        filter: 'snmp'
        dest: "{{config_dir}}/{{inventory_hostname}}.conf"
      register: config_result
    - name: retrieve config with (collection) juniper.device.config (WORKING) debug
      debug:
        msg: 
          - '{{config_result.msg}}'

    # Applying config with (role) juniper.junos.juniper_junos_config (Workaround)
    - name: apply config with (role) juniper.junos.juniper_junos_config (Workaround)
      # juniper.device.config: 
      juniper_junos_config:
        load: "replace"
        src: "{{config_dir}}/{{inventory_hostname}}_system.conf"
        diff: true
        commit: true
        comment: "ansible playbook {{ansible_play_name}}, commit confirm"
        timeout: 50
        confirm: 5
      register: config_result
    - name: apply config with (role) juniper.junos.juniper_junos_config (Workaround) debug
      debug:
        msg: 
          - '{{config_result.msg}}'

Task Output

PLAY [Juniper apply configuration workaround for ISSUE https://github.com/Juniper/ansible-junos-stdlib/issues/565] *************

TASK [retrieve config with (collection) juniper.device.config (WORKING)] *******************************************************
ok: [lab-juniper-ex2300]

TASK [retrieve config with (collection) juniper.device.config (WORKING) debug] *************************************************
ok: [lab-juniper-ex2300] => {
    "msg": [
        "Configuration has been: opened, retrieved, closed."
    ]
}

TASK [apply config with (role) juniper.junos.juniper_junos_config (Workaround)] ************************************************
changed: [lab-juniper-ex2300]

TASK [apply config with (role) juniper.junos.juniper_junos_config (Workaround) debug] ******************************************
ok: [lab-juniper-ex2300] => {
    "msg": [
        "Configuration has been: opened, loaded, checked, diffed, committed, closed."
    ]
}

PLAY RECAP *********************************************************************************************************************
lab-juniper-ex2300 : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Environment

requirements.txt

ansible==5.9.0
ansible-core==2.12.6
bcrypt==3.2.2
boto3==1.24.19
botocore==1.27.19
cffi==1.15.0
cryptography==37.0.2
ecdsa==0.17.0
Jinja2==3.1.2
jmespath==1.0.1
junos-eznc==2.6.4
jxmlease==1.0.3
lxml==4.9.0
MarkupSafe==2.1.1
ncclient==0.6.13
netaddr==0.8.0
packaging==21.3
paramiko==2.8.1
pycparser==2.21
pycrypto==2.6.1
PyNaCl==1.5.0
pyparsing==3.0.9
pyserial==3.5
python-dateutil==2.8.2
PyYAML==6.0
resolvelib==0.5.4
s3transfer==0.6.0
scp==0.14.4
six==1.16.0
transitions==0.8.11
urllib3==1.26.9
xmltodict==0.13.0
yamlordereddictloader==0.4.0

ansible-galaxy

ansible-galaxy collection list
Collection     Version
-------------- -------
juniper.device 1.0.1

ansible-galaxy role list
- juniper.junos, 2.4.3
dineshbaburam91 commented 9 months ago

638 fix the issue