Closed 33Fraise33 closed 9 months 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}
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
\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}
Yeah same thing is happening to me as well using ansible_connection: juniper.device.pyez
. When I run ansible_connection: local
it works
- 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
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
}
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.
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…
- 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}}'
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
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
Issue Type
Module Name
juniper.device.config
juniper.device collection and Python libraries version
OS / Environment
Juniper EX3400
JUNOS 20.4R2-S1.6
Summary
Running
juniper.device.config
with a template does not work withjuniper.device.pyez
as connection type.Steps to reproduce
change connection type from
ansible_connection: local
toansible_connection: juniper.device.pyez
Expected results
Actual results