junos_config – Manage configuration on devices running Juniper JUNOS

New in version 2.1.

Synopsis

  • This module provides an implementation for working with the active configuration running on Juniper JUNOS devices. It provides a set of arguments for loading configuration, performing rollback operations and zeroing the active configuration on the device.

Requirements

The below requirements are needed on the host that executes this module.

  • ncclient (>=v0.5.2)

Parameters

Parameter Choices/Defaults Comments
backup
boolean
added in 2.2
    Choices:
  • no ←
  • yes
This argument will cause the module to create a full backup of the current running-config from the remote device before any changes are made. The backup file is written to the backup folder in the playbook root directory or role root directory, if playbook is part of an ansible role. If the directory does not exist, it is created.
comment
-
Default:
"configured by junos_config"
The comment argument specifies a text string to be used when committing the configuration. If the confirm argument is set to False, this argument is silently ignored.
confirm
-
Default:
0
The confirm argument will configure a time out value in minutes for the commit to be confirmed before it is automatically rolled back. If the confirm argument is set to False, this argument is silently ignored. If the value for this argument is set to 0, the commit is confirmed immediately.
confirm_commit
boolean
added in 2.4
    Choices:
  • no ←
  • yes
This argument will execute commit operation on remote device. It can be used to confirm a previous commit.
lines
-
This argument takes a list of set or delete configuration lines to push into the remote device. Each line must start with either set or delete. This argument is mutually exclusive with the src argument.
provider
-
Deprecated
Starting with Ansible 2.5 we recommend using connection: network_cli or connection: netconf.
For more information please see the Junos OS Platform Options guide.

A dict object containing connection details.
host
- / required
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
password
-
Specifies the password to use to authenticate the connection to the remote device. This value is used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
port
-
Default:
22
Specifies the port to use when building the connection to the remote device. The port value will default to the well known SSH port of 22 (for transport=cli) or port 830 (for transport=netconf) device.
ssh_keyfile
-
Specifies the SSH key to use to authenticate the connection to the remote device. This value is the path to the key used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
timeout
-
Default:
10
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error.
username
-
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
replace
boolean
    Choices:
  • no ←
  • yes
The replace argument will instruct the remote device to replace the current configuration hierarchy with the one specified in the corresponding hierarchy of the source configuration loaded from this module.
Note this argument should be considered deprecated. To achieve the equivalent, set the update argument to replace. This argument will be removed in a future release. The replace and update argument is mutually exclusive.
rollback
-
The rollback argument instructs the module to rollback the current configuration to the identifier specified in the argument. If the specified rollback identifier does not exist on the remote device, the module will fail. To rollback to the most recent commit, set the rollback argument to 0.
src
-
added in 2.2
The src argument provides a path to the configuration file to load into the remote system. The path can either be a full system path to the configuration file if the value starts with / or relative to the root of the implemented role or playbook. This argument is mutually exclusive with the lines argument.
src_format
-
added in 2.2
    Choices:
  • xml
  • set
  • text
  • json
The src_format argument specifies the format of the configuration found int src. If the src_format argument is not provided, the module will attempt to determine the format of the configuration file specified in src.
update
-
added in 2.3
    Choices:
  • merge ←
  • override
  • replace
This argument will decide how to load the configuration data particulary when the candidate configuration and loaded configuration contain conflicting statements. Following are accepted values. merge combines the data in the loaded configuration with the candidate configuration. If statements in the loaded configuration conflict with statements in the candidate configuration, the loaded statements replace the candidate ones. override discards the entire candidate configuration and replaces it with the loaded configuration. replace substitutes each hierarchy level in the loaded configuration for the corresponding level.
zeroize
-
The zeroize argument is used to completely sanitize the remote device configuration back to initial defaults. This argument will effectively remove all current configuration statements on the remote device.

Notes

Note

  • This module requires the netconf system service be enabled on the remote device being managed.
  • Abbreviated commands are NOT idempotent, see Network FAQ.
  • Loading JSON-formatted configuration json is supported starting in Junos OS Release 16.1 onwards.
  • Update override not currently compatible with set notation.
  • Tested against vSRX JUNOS version 15.1X49-D15.4, vqfx-10000 JUNOS Version 15.1X53-D60.4.
  • Recommended connection is netconf. See the Junos OS Platform Options.
  • This module also works with local connections for legacy playbooks.
  • For information on using CLI and netconf see the Junos OS Platform Options guide
  • For more information on using Ansible to manage network devices see the Ansible Network Guide
  • For more information on using Ansible to manage Juniper network devices see https://www.ansible.com/ansible-juniper.

Examples

- name: load configure file into device
  junos_config:
    src: srx.cfg
    comment: update config

- name: load configure lines into device
  junos_config:
    lines:
      - set interfaces ge-0/0/1 unit 0 description "Test interface"
      - set vlans vlan01 description "Test vlan"
    comment: update config

- name: Set routed VLAN interface (RVI) IPv4 address
  junos_config:
    lines:
      - set vlans vlan01 vlan-id 1
      - set interfaces irb unit 10 family inet address 10.0.0.1/24
      - set vlans vlan01 l3-interface irb.10

- name: rollback the configuration to id 10
  junos_config:
    rollback: 10

- name: zero out the current configuration
  junos_config:
    zeroize: yes

- name: Set VLAN access and trunking
  junos_config:
    lines:
      - set vlans vlan02 vlan-id 6
      - set interfaces ge-0/0/6.0 family ethernet-switching interface-mode access vlan members vlan02
      - set interfaces ge-0/0/6.0 family ethernet-switching interface-mode trunk vlan members vlan02

- name: confirm a previous commit
  junos_config:
    confirm_commit: yes

- name: for idempotency, use full-form commands
  junos_config:
    lines:
      # - set int ge-0/0/1 unit 0 desc "Test interface"
      - set interfaces ge-0/0/1 unit 0 description "Test interface"

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
backup_path
string
when backup is yes
The full path to the backup file

Sample:
/playbooks/ansible/backup/config.2016-07-16@22:28:34


Status

Red Hat Support

More information about Red Hat’s support of this module is available from this Red Hat Knowledge Base article.

Authors

  • Peter Sprygada (@privateip)

Hint

If you notice any issues in this documentation you can edit this document to improve it.