Netconf enabled Platform Options

This page offers details on how the netconf connection works in Ansible 2.7 and how to use it.

Connections Available

* all modules except junos_netconf, which enables NETCONF
Protocol XML over SSH

uses SSH keys / SSH-agent if present
accepts -u myuser -k if using password
Indirect Access via a bastion (jump host)
Connection Settings ansible_connection: netconf

For legacy playbooks, Ansible still supports ansible_connection=local for the netconf_config module only. We recommend modernizing to use ansible_connection=netconf as soon as possible.

Using NETCONF in Ansible 2.6 onwards

Enabling NETCONF

Before you can use NETCONF to connect to a switch, you must:

  • install the ncclient Python package on your control node(s) with pip install ncclient
  • enable NETCONF on the Junos OS device(s)

To enable NETCONF on a new switch via Ansible, use the platform specific module via the CLI connection or set it manually. For example set up your platform-level variables just like in the CLI example above, then run a playbook task like this:

- name: Enable NETCONF
  connection: network_cli
  when: ansible_network_os == 'junos'

Once NETCONF is enabled, change your variables to use the NETCONF connection.

Example NETCONF inventory [junos:vars]

ansible_ssh_pass=!vault |

Example NETCONF Task

- name: Backup current switch config
    backup: yes
  register: backup_junos_location

Example NETCONF Task with configurable variables

- name: configure interface while providing different private key file path
    backup: yes
  register: backup_junos_location
    ansible_private_key_file: /home/admin/.ssh/newprivatekeyfile

Note: For nectonf connection plugin configurable variables .. _Refer:


Never store passwords in plain text. We recommend using SSH keys to authenticate SSH connections. Ansible supports ssh-agent to manage your SSH keys. If you must use passwords to authenticate SSH connections, we recommend encrypting them with Ansible Vault.