Not able to push playbook to Juniper Switch

I am unable to push playbook tasks to our Juniper switch. If I just create a simple playbook for gathering the facts, I am getting below error “[Errno -2] Name or service not known”. and this error is same for every module.
Connectivity is fine as I am able to ssh the Juniper switch from the Ansible server.
I am pasting the playbook below as well as the error with -vvvv.

Please find my Playbook.

- hosts: juniperswitch
  gather_facts: no
     ansible_command_timeout: 1800

    - name: get the facts
      register: value1

    - name: Print in screen
        var: value1

error after adding -vvvv.

The full traceback is:
  File "/root/.ansible/collections/ansible_collections/ansible/netcommon/plugins/module_utils/network/common/", line 215, in get_capabilities
    capabilities = Connection(module._socket_path).get_capabilities()
  File "/usr/local/lib/python3.8/site-packages/ansible/module_utils/", line 200, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: []: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "available_network_resources": false,
            "config_format": "text",
            "gather_network_resources": null,
            "gather_subset": [
    "msg": "[Errno -2] Name or service not known"

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

Hey @G24joshi can you provide an inventory so I can see how you setup your ansible_network_os?

Hi @IPvSean

Thanks, Please find below hosts file and group_vars file for my juniper switch.

[root@lonans01 juniperymls]# cat /etc/ansible/hosts
[root@lonans01 juniperymls]# cat /etc/ansible/group_vars/juniperswitch
ansible_network_os: junos
ansible_user: admin.b1
ansible_password: Pass@#$$
ansible_connection: netconf
ansible_become: yes
ansible_become_method: enable
ansible_become_password: Pass@#$$
[root@lonans01 juniperymls]#

Two question/requests:

  1. Is netconf enabled on the Juniper device? You can use the junos_netconf module to enable it: junipernetworks.junos.junos_netconf module – Configures the Junos Netconf system service — Ansible Documentation

You can see how I use it here:

  1. Can you re-run your playbook with -vvvv (4 vs) so I can see what it is doing for the connection?

After enabling netconf in Juniper Device it now working. Thanks a lot. I run below command in juniper device to enable Netconf

set system services netconf ssh port 830


Hi G24joshi,

Thanks for posting an update indicating that the issue was solved, if @IPvSean 's post helped you, please make sure to check the tick in his comment as the solution.

I’m sharing a small guide on how to do it below:


If you get to a point where you consider a post by someone helped you to solve the issue, please tick :white_check_mark: the check-box below their message:


This will mark the message as the solution and show it in the first post for easy access, as well as recognize the person that helped:


Thank you again and let us know if you have any questions or doubts!


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.