'JuniperJunosModule' object has no attribute 'conn_type'

622 views
Skip to first unread message

Andrey Kostin

unread,
May 25, 2021, 4:11:09 PM5/25/21
to Junos Python EZ

Looks like I'm missing something obvious but can't find it.
I have two playbooks, the first one works:

---
- name: Get device facts
  hosts:
    - all
  collections:
    - juniper.device
  connection: local
  gather_facts: no

  tasks:
    - name: get facts using galaxy module
      facts:
        host: "{{ ansible_host }}"
    - name: Print output
      debug:
        var: inventory_hostname
        var: ansible_host
        var: junos.version, junos.hostname, junos.serialnumber

But this one doesn't work and throws the error:
---
- name: Get config from Juniper device
  hosts:
    - all
  collections:
    - juniper.device
  connection: local
  gather_facts: no

  vars:
      config_filter: "<groups><name>common:system</name></groups>"

  tasks:
    - name: get config from device
      config:
        host: "{{ ansible_host }}"
        retrive: commited
        format: text
        filter: "{{ config_filter }}"
        dest_dir: "../configs/"
        return_output: yes
      register: response
    - name: Print config lines
      debug:
        var: response.config_lines

The error is:
TASK [get config from device] ********************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'JuniperJunosModule' object has no attribute 'conn_type'

I'm using ssh key in default location and it works with the first playbook, what's the problem with the second one?
I also tried to explicitly specify username and ssh key file but result was the same. It makes me thinking that problem might be with something else and error message is misleading.

Kind regards,
Andrey

Rahul Kumar

unread,
May 26, 2021, 3:11:42 AM5/26/21
to Andrey Kostin, Junos Python EZ
Hi Andrey, 

The issue seems to be there because of a typing mistake in "retrive: commited" parameter. 


tasks:
    - name: get config from device
      config:
        host: "{{ ansible_host }}"
        retrieve: committed

Once the spelling is corrected, it will work fine. 

The error displayed is wrong in this case and it needs to be handled properly. Thanks for bringing it to our notice, we will modify the error handling for the scenario. 

Regards
Rahul Kumar


From: junos-p...@googlegroups.com <junos-p...@googlegroups.com> on behalf of Andrey Kostin <anko...@gmail.com>
Sent: 26 May 2021 01:41
To: Junos Python EZ <junos-p...@googlegroups.com>
Subject: 'JuniperJunosModule' object has no attribute 'conn_type'
 

[External Email. Be cautious of content]

--
You received this message because you are subscribed to the Google Groups "Junos Python EZ" group.
To unsubscribe from this group and stop receiving emails from it, 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/ecdbd0e0-f626-4d36-a3de-c8090a25a482n%40googlegroups.com.

Juniper Business Use Only

Andrey Kostin

unread,
May 26, 2021, 8:39:55 AM5/26/21
to Junos Python EZ
Thank you very much, Rahul, for pointing it out. Unfortunately, the error hasn't gone :(
Corrected playbook:

---
- name: Get config from Juniper device
  hosts:
    - all
  collections:
    - juniper.device
  connection: local
  gather_facts: no

  vars:
      config_filter: "<groups><name>common:system</name></groups>"

#  vars_prompt:
#    - name: username
#      prompt: Junos Username
#      private: no
#    - name: password
#      prompt: Junos Password
#      private: yes


  tasks:
    - name: get config from device
      config:
        host: "{{ ansible_host }}"
        retrive: committed

        format: text
        filter: "{{ config_filter }}"
        dest_dir: "../configs/"
        return_output: yes
      register: response
    - name: Print config lines
      debug:
        var: response.config_lines

Playbook output:
$ ansible-playbook playbooks/juniper.device_get_config.yaml -l lns01.lab
[DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to allow bad characters in group names by default, this will change, but still be
user configurable on deprecation. This feature will be removed in version 2.10. Deprecation warnings can be disabled by setting deprecation_warnings=False in
 ansible.cfg.
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [Get config from Juniper device] ************************************************************************************************************************


TASK [get config from device] ********************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'JuniperJunosModule' object has no attribute 'conn_type'
fatal: [lns01.lab]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/akostin/.ansible/tmp/ansible-tmp-1622032378.9693487-280082289088187/AnsiballZ_config.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/akostin/.ansible/tmp/ansible-tmp-1622032378.9693487-280082289088187/AnsiballZ_config.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/akostin/.ansible/tmp/ansible-tmp-1622032378.9693487-280082289088187/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/local/lib/python3.8/runpy.py\", line 206, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/local/lib/python3.8/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/local/lib/python3.8/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_config_payload_yk3dsm2o/ansible_config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1164, in <module>\n  File \"/tmp/ansible_config_payload_yk3dsm2o/ansible_config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 777, in main\n  File \"/tmp/ansible_config_payload_yk3dsm2o/ansible_config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 570, in __init__\n  File \"/tmp/ansible_config_payload_yk3dsm2o/ansible_config_payload.zip/ansible/module_utils/basic.py\", line 657, in __init__\n  File \"/tmp/ansible_config_payload_yk3dsm2o/ansible_config_payload.zip/ansible/module_utils/basic.py\", line 1494, in _check_arguments\n  File \"/tmp/ansible_config_payload_yk3dsm2o/ansible_config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 722, in fail_json\n  File \"/tmp/ansible_config_payload_yk3dsm2o/ansible_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 ***************************************************************************************************************************************************
lns01.lab                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

I run it from venv with Python 3.8, just for the case.

Rahul Kumar

unread,
May 26, 2021, 8:59:21 AM5/26/21
to Andrey Kostin, Junos Python EZ
Hi Andrey, 

You just corrected the "committed" , there is typing mistake in "retrieve" also. there is a missing "e". 

Regards
Rahul Kumar


Sent: 26 May 2021 18:09

To: Junos Python EZ <junos-p...@googlegroups.com>
Subject: Re: 'JuniperJunosModule' object has no attribute 'conn_type'
 

Andrey Kostin

unread,
Jun 1, 2021, 4:10:25 PM6/1/21
to Rahul Kumar, Junos Python EZ
Exactly! I didn't see your message but today I found it myself with fresh look. Now it's working. I could only wish the error message were more specific. Thanks for your help!

Kind regards,
Andrey

Daniel Walker

unread,
Jun 17, 2021, 1:55:11 PM6/17/21
to Junos Python EZ
newbie with this Ansible and I'm trying a simple juniper Ansible playbook:

- 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 !!



Rahul Kumar

unread,
Jun 18, 2021, 6:14:20 AM6/18/21
to Daniel Walker, Junos Python EZ
Hi Daniel, 

There seems to be an issue with your top part of playbook. 

Instead of this ---->

- name: update snmp host

  hosts: a2n

  roles:

   - Juniper.junos

  connection: juniper.device.pyez

  gather_facts: no



You should use something like ----> 

- name: update snmp host

  hosts: a2n

  collections:
    - juniper.device

  connection: juniper.device.pyez

  gather_facts: no


Just to provide some more details, Ansible supported roles intially and Juniper team created Juniper.junos(roles) for juniper devices which is compatible with Ansible. Ansible recently changed their design, and in newer ones, they will be deprecating the roles and will only be supporting collections. Collections has made ansible independent of customer supported libraries. Juniper team has now created juniper.device(collections) and is currently working on it. 

Regards
Rahul Kumar



From: junos-p...@googlegroups.com <junos-p...@googlegroups.com> on behalf of Daniel Walker <dwal...@uw.edu>
Sent: 17 June 2021 23:25

Dan Walker

unread,
Jun 18, 2021, 8:48:11 AM6/18/21
to Rahul Kumar, Junos Python EZ

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 }}"

         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

 

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 }}"

         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

 

 

Daniel Walker B.S / B.A

/var/folders/ct/vd5cx9151294l5j_5v76q5r00000gn/T/com.microsoft.Outlook/WebArchiveCopyPasteTempFiles/cidimage013.png@01D5697F.B7079C30

Senior Network Engineer
Networks and Threat Protection  IT Services | UW Medicine

OFFICE:    206.616.7024

EMAIL   dwal...@uw.edu    WEB: uwmedicine.org

 

 

cidimage010.png@01D5EBF8.7CE18970  cidimage011.png@01D5EBF8.7CE18970  cidimage012.png@01D5EBF8.7CE18970  cidimage013.png@01D5EBF8.7CE18970  cidimage014.png@01D5EBF8.7CE18970

--
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.

Rahul Kumar

unread,
Jun 18, 2021, 9:00:52 AM6/18/21
to Dan Walker, Junos Python EZ
Hi Dan, 

As mentioned in the previous reply, you seem to be mixing roles and collection. In previous playbook, you had task as juniper.device.config(which is part of collection module) while in this example you have mentioned juniper_junos_config(which is part of roles module). I would recommend you go through this link as it has well explained information with examples of how to use juniper created ansible modules. 
https://www.juniper.net/documentation/en_US/junos-ansible/information-products/pathway-pages/junos-ansible.html

Regarding the below query - 

 Question:  can you actually compare a configuration BEFORE making changes via an ansible playbook?

Yes, it is possible. It depends on what exactly you want to compare. 
https://www.juniper.net/documentation/en_US/junos-ansible/topics/topic-map/junos-ansible-configuration-retrieving.html ---> This link has got examples for the same. Check for retrieve and rollback and you will get multiple working examples. 

Regards
Rahul Kumar



From: Dan Walker <dwal...@uw.edu>
Sent: 18 June 2021 18:17
To: Rahul Kumar <rahk...@juniper.net>; Junos Python EZ <junos-p...@googlegroups.com>

Juniper Business Use Only


Juniper Business Use Only

Dan Walker

unread,
Jun 18, 2021, 9:08:44 AM6/18/21
to Rahul Kumar, Junos Python EZ

Thank again for your response, I’ll take a look and try out the newer methods.   

Dan Walker

unread,
Jun 18, 2021, 2:17:43 PM6/18/21
to Rahul Kumar, Junos Python EZ

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

 

Graphical user interface, text

Description automatically generated

Rahul Kumar

unread,
Jun 21, 2021, 4:17:52 AM6/21/21
to Dan Walker, Junos Python EZ
Hi Dan, 

To use juniper-maintained collection you need to replace the below step 
ansible-galaxy collection install junipernetworks.junos
to 
ansible-galaxy collection install juniper.device

The error seems to be because of the path. By default the path of installtion is "~/.ansible/roles/ ".
The path where it is searching is different. You can modify the environment variable or can modify the path where ansible is installing the roles/collections. 

You can also copy paste the complete content of  ~/.ansible/​ to
/etc/ansible/

Regards
Rahul Kumar

From: junos-p...@googlegroups.com <junos-p...@googlegroups.com> on behalf of Dan Walker <dwal...@uw.edu>
Sent: 18 June 2021 23:47

Juniper Business Use Only


Juniper Business Use Only

Dan Walker

unread,
Jun 21, 2021, 10:57:33 AM6/21/21
to Rahul Kumar, Junos Python EZ

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"

Dan Walker

unread,
Jun 21, 2021, 4:14:27 PM6/21/21
to Rahul Kumar, Junos Python EZ

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.

 

 

Text, letter

Description automatically generated

Rahul Kumar

unread,
Jun 22, 2021, 7:22:48 AM6/22/21
to Dan Walker, Junos Python EZ
Hi Dan, 

"provider" is not supported in collections. It is causing the error. 

I would recommend you go through these links. They have a lot of working examples which will cover most of your scenario's. 

You can refer this to find all the parameter supported in a collection-module(tasks) - https://ansible-juniper-collection.readthedocs.io/en/latest/config.html

Refer these two links specifically for login related information and configuration retrieval. 

https://www.juniper.net/documentation/en_US/junos-ansible/topics/topic-map/junos-ansible-connection-methods.html
https://www.juniper.net/documentation/en_US/junos-ansible/topics/topic-map/junos-ansible-configuration-retrieving.html 

For connection: juniper.device.pyez , It is recommended to use "vars" in the playbook or inventory file method. 

"connection: juniper.device.pyez" is specific for persistent connection. As you are running a single task, you can execute with "connection:local" and just remove the parameter "provider". The other parameters like user, passwd, host can be directly passed to the task. 

Regards
Rahul Kumar


From: Dan Walker <dwal...@uw.edu>
Sent: 21 June 2021 20:26

Juniper Business Use Only

Dan Walker

unread,
Jun 28, 2021, 4:11:26 PM6/28/21
to Rahul Kumar, Junos Python EZ

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     

Dan Walker

unread,
Jun 28, 2021, 5:08:17 PM6/28/21
to Rahul Kumar, Junos Python EZ

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

Dan Walker

unread,
Jul 20, 2021, 3:47:32 PM7/20/21
to Rahul Kumar, Junos Python EZ

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)"

Rahul Kumar

unread,
Jul 21, 2021, 11:42:25 PM7/21/21
to Dan Walker, Junos Python EZ
Hi Dan, 

It seems there is some problem with the device ssh connection. Could you try the ssh connection with netconf protocol on the device and share the output? 

eg - ssh <user>@<ip> -s netconf 

If the above works fine. share the output of ansible script in verbose mode. 

eg - ansible-playbook play.yml -vvv

Regards
Rahul Kumar


Sent: 21 July 2021 01:16

Juniper Business Use Only


Juniper Business Use Only

Dan Walker

unread,
Jul 22, 2021, 10:54:53 AM7/22/21
to Rahul Kumar, Junos Python EZ

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

Dan Walker

unread,
Aug 10, 2021, 12:18:15 PM8/10/21
to Rahul Kumar, Junos Python EZ

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

/var/folders/ct/vd5cx9151294l5j_5v76q5r00000gn/T/com.microsoft.Outlook/WebArchiveCopyPasteTempFiles/cidimage013.png@01D5697F.B7079C30

Senior Network Engineer
Networks and Threat Protection  IT Services | UW Medicine

OFFICE:    206.616.7024

EMAIL   dwal...@uw.edu    WEB: uwmedicine.org

 

 

cidimage010.png@01D5EBF8.7CE18970  cidimage011.png@01D5EBF8.7CE18970  cidimage012.png@01D5EBF8.7CE18970  cidimage013.png@01D5EBF8.7CE18970  cidimage014.png@01D5EBF8.7CE18970

 

 

Rahul Kumar

unread,
Aug 12, 2021, 12:44:42 AM8/12/21
to Dan Walker, Junos Python EZ
Hi Dan, 

Below is the filter which will work for you. 
filter: "<vlans><vlan><name>VLAN611</name></vlan></vlans>"

To get proper syntax of filter you can login to your device and go to cli and execute command like this. It will help you create filters. 

show configuration vlans | display xml 


Regards
Rahul kumar


From: Dan Walker <dwal...@uw.edu>
Sent: 10 August 2021 21:46

Juniper Business Use Only

Reply all
Reply to author
Forward
0 new messages