Juniper Business Use Only
Juniper Public
- name: update snmp host
hosts: a2n
roles:
- Juniper.junos
connection: juniper.device.pyez
gather_facts: no
vars_prompt:
- name: username
prompt: local usename
private: no
- name: password
prompt: Junos Password
private: yes
tasks:
- name: update snmp client list
juniper.device.config:
config_mode: "private"
load: "set"
lines:
- "set snmp client-list solarwinds 10.67.190.131/32"
- "set snmp client-list solarwinds 10.67.190.131/32"
register: response
- name: "Print the response"
debug:
var: response
When I run it, will prompt for username & password, but fails with:
TASK [update snmp client list] ***************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'JuniperJunosModule' object has no attribute 'conn_type'
[WARNING]: Platform linux on host a2n is using the discovered Python interpreter at /bin/python3.6, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
fatal: [a2n]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/bin/python3.6"}, "changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/root/.ansible/tmp/ansible-local-799753_mgaxon/ansible-tmp-1623952196.6154227-79982-257960205066571/AnsiballZ_config.py\", line 102, in <module>\n _ansiballz_main()\n File \"/root/.ansible/tmp/ansible-local-799753_mgaxon/ansible-tmp-1623952196.6154227-79982-257960205066571/AnsiballZ_config.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/root/.ansible/tmp/ansible-local-799753_mgaxon/ansible-tmp-1623952196.6154227-79982-257960205066571/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/lib64/python3.6/runpy.py\", line 205, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n mod_name, mod_spec, pkg_name, script_name)\n File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_juniper.device.config_payload_zd2528yu/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_zd2528yu/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 887, in main\n File \"/tmp/ansible_juniper.device.config_payload_zd2528yu/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 573, in __init__\n File \"/tmp/ansible_juniper.device.config_payload_zd2528yu/ansible_juniper.device.config_payload.zip/ansible/module_utils/basic.py\", line 748, in __init__\n File \"/tmp/ansible_juniper.device.config_payload_zd2528yu/ansible_juniper.device.config_payload.zip/ansible/module_utils/basic.py\", line 1593, in _check_arguments\n File \"/tmp/ansible_juniper.device.config_payload_zd2528yu/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 722, in fail_json\n File \"/tmp/ansible_juniper.device.config_payload_zd2528yu/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1163, in close_configuration\nAttributeError: 'JuniperJunosModule' object has no attribute 'conn_type'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
PLAY RECAP ***********************************************************************************************************************************************************************************************
a2n : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
ANY HELP WOULD BE APPREICATED.. DRIVING ME NUTS !!
- name: update snmp host
hosts: a2n
roles:
- Juniper.junos
connection: juniper.device.pyez
gather_facts: no
- name: update snmp host
hosts: a2n
connection: juniper.device.pyez
gather_facts: no
Juniper Business Use Only
Rahul
Note: just getting started with this Ansible tool, I hope to expand my playbooks to include pulling configs, comparing configurations.
Question: can you actually compare a configuration BEFORE making changes via an ansible playbook?
Thank you for this. I did try it and we’ll did not work for me:
[root@njb-lab-centos8-localdomain playbooks]# ansible-playbook junos_snmp.yaml
[WARNING]: Ansible is being run in a world writable directory (/etc/ansible/playbooks), ignoring it as an ansible.cfg source. For more information see
https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir
ERROR! couldn't resolve module/action 'juniper_junos_config'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/etc/ansible/playbooks/junos_snmp.yaml': line 22, column 8, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: update snmp client list
^ here
here is my playbook: that does NOT work
===================================
---
- name: update snmp host
hosts:
- all
collections:
- Juniper.device
connection: local
gather_facts: no
vars_prompt:
- name: username
prompt: local usename
private: no
- name: password
prompt: Junos Password
private: yes
vars:
tmp_dir: "/etc/ansible/playbooks"
tasks:
- name: update snmp client list
juniper_junos_config:
host: "{{ ansible_host }}"
port: "22"
user: "{{ username }}"
passwd: "{{ password }}"
- set snmp client-list solarwinds 10.67.190.132/32
format: text
check_commit_wait: 4
check: true
commit: true
register: response
- name: Print the response
debug:
var: response
Working playbook -
========================================================================
---
- name: update snmp host
hosts:
- all
roles:
- Juniper.junos
connection: local
gather_facts: no
vars_prompt:
- name: username
prompt: local usename
private: no
- name: password
prompt: Junos Password
private: yes
vars:
tmp_dir: "/etc/ansible/playbooks"
tasks:
- name: update snmp client list
juniper_junos_config:
host: "{{ ansible_host }}"
port: "22"
user: "{{ username }}"
passwd: "{{ password }}"
- set snmp client-list solarwinds 10.67.190.132/32
format: text
check_commit_wait: 4
check: true
commit: true
register: response
- name: Print the response
debug:
var: response
Daniel Walker B.S / B.A
![]()
Senior Network Engineer
Networks and Threat Protection IT Services | UW
Medicine
OFFICE: 206.616.7024
EMAIL: dwal...@uw.edu WEB: uwmedicine.org
--
You received this message because you are subscribed to a topic in the Google Groups "Junos Python EZ" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/junos-python-ez/tj96UllAM4g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
junos-python-...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/junos-python-ez/DM6PR05MB4714561F6DF4E2C02F4616DDCF0D9%40DM6PR05MB4714.namprd05.prod.outlook.com.
Juniper Business Use Only
Juniper Business Use Only
Thank again for your response, I’ll take a look and try out the newer methods.
Rahul;
we’ll got this working, but then I got fancy and installed Ansible Tower and now playbooks that worked before now do not work. error msg:
I did do
ansible-galaxy collection install junipernetworks.junos
pip3 install junos-eznc
ansible-galaxy install Juniper.junos
pip3 install jxmlease
· sudo yum install python3-argcomplete
· install python2 then python3
o [root@njb-lab-centos8-localdomain ~]# dnf install python2-pip
· Then install junos-eznc
o [root@njb-lab-centos8-localdomain ~]# pip3 install junos-eznc
·
· Need install jxmlease "pip3 install jxmlease"
· ansible-galaxy install juniper.junos
· ansible-galaxy collection install junipernetworks.junos
More support libraries to install
[root@njb-lab-centos8-localdomain playbooks]# pip3 install xmltodict
but still

~/.ansible/ to
/etc/ansible/
Juniper Business Use Only
Juniper Business Use Only
thank you again; never been a great programmer:
this is the one msg I always seem to get but do not understand why?
TASK [get commited configuration] ********************************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'JuniperJunosModule' object has no attribute 'conn_type'
such a simple .yml playbook
---
- name: Get Current Configuration
hosts:
- njb-lab-esw-la-a2n
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
tasks:
- name: get commited configuration
juniper.device.config:
retrieve: "committed"
provider:
host: "{{ ansible_host }}"
port: "22"
user: "{{ username }}"
passwd: "{{ password }}"
register: reponse
- name: "Print Results"
Sorry for so many questions:
When running a playbook via the cli that works, and then trying to run via Ansible Tower, it does not work.
Usually get this error msg:
I’ve edited the inventory file located in the /var/lib/awx/projects
home folder: /var/lib/awx
I’ve been reading the document links you sent to me but to no avail.

Juniper Business Use Only
after reading and trying to understand, I’m still failing. On one I was able to get the playbook running, but now moving on to junipernetworks.junos.junos_config or junipernetworks.junos.junos_vlan. Unable to get it to work;
error msg:
[WARNING]: ['connection local support for this module is deprecated and will be removed in version 2.14, use connection ansible.netcommon.netconf']
fatal: [njb-lab-esw-la-a2n]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"}, "changed": false, "module_stderr": "", "module_stdout": "\n{\"msg\": \"connect() got an unexpected keyword argument 'sock'\", \"failed\": true, \"invocation\": {\"module_args\": {\"aggregate\": [{\"vlan_id\": 999, \"name\": \"test_vlan_999\", \"description\": \"test-vlan\", \"interfaces\": null, \"l3_interface\": null, \"filter_input\": null, \"filter_output\": null, \"state\": \"present\", \"active\": true}], \"description\": \"test-vlan\", \"state\": \"present\", \"provider\": {\"host\": null, \"port\": null, \"username\": null, \"password\": null, \"ssh_keyfile\": null, \"timeout\": null, \"transport\": \"netconf\"}, \"active\": true, \"name\": null, \"vlan_id\": null, \"interfaces\": null, \"l3_interface\": null, \"filter_input\": null, \"filter_output\": null}}, \"deprecations\": [{\"msg\": \"Param 'provider' is deprecated. See the module docs for more information\", \"version\": null}]}\n\n{\"msg\": \"connect() got an unexpected keyword argument 'sock'\", \"failed\": true, \"invocation\": {\"module_args\": {\"aggregate\": [{\"vlan_id\": 999, \"name\": \"test_vlan_999\", \"description\": \"test-vlan\", \"interfaces\": null, \"l3_interface\": null, \"filter_input\": null, \"filter_output\": null, \"state\": \"present\", \"active\": true}], \"description\": \"test-vlan\", \"state\": \"present\", \"provider\": {\"host\": null, \"port\": null, \"username\": null, \"password\": null, \"ssh_keyfile\": null, \"timeout\": null, \"transport\": \"netconf\"}, \"active\": true, \"name\": null, \"vlan_id\": null, \"interfaces\": null, \"l3_interface\": null, \"filter_input\": null, \"filter_output\": null}}, \"deprecations\": [{\"msg\": \"Param 'provider' is deprecated. See the module docs for more information\", \"version\": null}]}\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
PLAY RECAP *************************************************************************************************************************************************************************************************************************************************************************************************
njb-lab-esw-la-a2n : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
[root@Centos8-NJB-LAB playbooks]#
playbook, so simple yet so many errors are generated.
I’ved used this resource: https://docs.ansible.com/ansible/latest/collections/junipernetworks/junos/junos_vlan_module.html#parameter-aggregate/name
and this resource: https://docs.ansible.com/ansible/latest/collections/junipernetworks/junos/junos_config_module.html
still no luck.
1 ---
2 - name: add vlan
3 hosts:
4 - njb-lab-esw-la-a2n
5 collections:
6 - juniper.device
7 connection: local
8 gather_facts: no
9
10 vars_prompt:
11 - name: username
12 prompt: local usename
13 private: no
14
15 - name: password
16 prompt: Junos Password
17 private: yes
18 vars:
19 tmp_dir: "/etc/ansible/playbooks"
20
21 tasks:
22 - name: create vlan
23 junipernetworks.junos.junos_vlan:
24 aggregate:
25 - {vlan_id: 999, name: test_vlan_999}
26 description: test-vlan
27 state: present
28 - name: commit
29 junipernetworks.junos.junos_config:
30 confirm_commit: yes
To view this discussion on the web visit
https://groups.google.com/d/msgid/junos-python-ez/DM6PR05MB47144AE53AF9315BFE8A5740CF099%40DM6PR05MB4714.namprd05.prod.outlook.com.
Rahul;
this is the document I’ve been referencing. But always seem have issues when I put together a playbook based on the junipernetwork.junos.junos_config for the collection
https://docs.ansible.com/ansible/latest/collections/junipernetworks/junos/junos_config_module.html
Greetings Rahul;
so been progressing and I have a playbook that works on some juniper switches but not on others. Here is output of one not working. Common error “
---
- name: update snmp host
hosts:
- njb-esw-ha-b-b18
collections:
- juniper.device
connection: local
gather_facts: no
vars_prompt:
- name: username
prompt: local usename
private: no
- name: password
prompt: Junos Password
private: yes
vars:
tmp_dir: "/etc/ansible/playbooks"
tasks:
- name: update snmp client list
juniper.device.config:
host: "{{ ansible_host }}"
port: "22"
user: "{{ username }}"
passwd: "{{ password }}"
load: set
lines:
- set snmp client-list solarwinds 10.67.190.131/32
- set snmp client-list solarwinds 10.67.190.132/32
format: text
check_commit_wait: 4
check: true
commit: true
register: response
- name: Print the response
debug:
var: response
~
"msg": "Unable to make a PyEZ connection: ConnectTimeoutError(10.68.17.182)"
The full traceback is:
File "/tmp/ansible_juniper.device.config_payload_mnhk7eev/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py", line 1069, in open
self.dev.open()
File "/usr/local/lib/python3.6/site-packages/jnpr/junos/device.py", line 1385, in open
raise EzErrors.ConnectTimeoutError(self)
fatal: [njb-esw-ha-b-b18]: FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"invocation": {
"module_args": {
"attempts": null,
"baud": null,
"check": true,
"check_commit_wait": 4,
"comment": null,
"commit": true,
"commit_empty_changes": false,
"config_mode": "exclusive",
"confirmed": null,
"console": null,
"cs_passwd": null,
"cs_user": null,
"dest": null,
"dest_dir": null,
"diff": null,
"diffs_file": null,
"filter": null,
"format": "text",
"host": "10.68.17.182",
"ignore_warning": null,
"level": null,
"lines": [
"set snmp client-list solarwinds 10.67.190.131/32",
"set snmp client-list solarwinds 10.67.190.132/32"
],
"load": "set",
"logdir": null,
"logfile": null,
"mode": null,
"model": null,
"namespace": null,
"options": {},
"passwd": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 22,
"remove_ns": null,
"retrieve": null,
"return_output": true,
"rollback": null,
"src": null,
"ssh_config": null,
"ssh_private_key_file": null,
"template": null,
"timeout": 10,
"url": null,
"user": "root",
"vars": null
}
},
"msg": "Unable to make a PyEZ connection: ConnectTimeoutError(10.68.17.182)"
Juniper Business Use Only
Juniper Business Use Only
Rahul;
thanks and the issue I found was that each junos switch had a different firewall configuration. When I updated the firewall rule, I was then able to connect. playbook works for all but one.
I appreciate all of the help, next it to try more complex playbooks. Also, do you know if there are specific roles / collections for other vendors? i.e. HP – Cisco ?
We are mostly a Juniper shop, but still have some lingering old HP / Cisco equipment
To view this discussion on the web visit
https://groups.google.com/d/msgid/junos-python-ez/DM6PR05MB4714B8716A305077A648F205CFE39%40DM6PR05MB4714.namprd05.prod.outlook.com.
Thanks as always://
I’m not having luck with filters in the playbooks.
I have found this resource for retrieving specific data: https://www.juniper.net/documentation/us/en/software/junos-ansible/ansible/topics/topic-map/junos-ansible-configuration-retrieving.html
I’ve tired to do this for vlans, but not working; here is what I tried:
- name: "Get VLAN Config"
juniper.device.config:
retrieve: "committed"
filter: "vlans<name>VLAN611</name>"
register: response
- name: "Print Results"
debug:
var: response
I can get “ALL” vlans but not just a single vlan.. what is a good source for filter vlans? ansible version 2.9
this works:
- name: "Get VLAN Config"
juniper.device.config:
retrieve: "committed"
filter: "vlans”
register: response
- name: "Print Results"
debug:
var: response
Daniel Walker B.S / B.A
![]()
Senior Network Engineer
Networks and Threat Protection IT Services | UW
Medicine
OFFICE: 206.616.7024
EMAIL: dwal...@uw.edu WEB: uwmedicine.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/junos-python-ez/DM6PR05MB47144AE53AF9315BFE8A5740CF099%40DM6PR05MB4714.namprd05.prod.outlook.com.
filter: "<vlans><vlan><name>VLAN611</name></vlan></vlans>"
show configuration vlans | display xml
Juniper Business Use Only