junipernetworks.junos.junos_config (8.0.0) — module

Manage configuration on devices running Juniper JUNOS

| "added in version" 1.0.0 of junipernetworks.junos"

Authors: Peter Sprygada (@privateip)

Install collection

Install with ansible-galaxy collection install junipernetworks.junos:==8.0.0


Add to requirements.yml

  collections:
    - name: junipernetworks.junos
      version: 8.0.0

Description

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

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: load configure file into device
  junipernetworks.junos.junos_config:
    src: srx.cfg
    comment: update config
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: load configure lines into device
  junipernetworks.junos.junos_config:
    lines:
      - set interfaces ge-0/0/1 unit 0 description "Test interface"
      - set vlans vlan01 description "Test vlan"
    comment: update config
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set routed VLAN interface (RVI) IPv4 address
  junipernetworks.junos.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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Check correctness of commit configuration
  junipernetworks.junos.junos_config:
    check_commit: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: rollback the configuration to id 10
  junipernetworks.junos.junos_config:
    rollback: 10
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: zero out the current configuration
  junipernetworks.junos.junos_config:
    zeroize: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set VLAN access and trunking
  junipernetworks.junos.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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: confirm a previous commit
  junipernetworks.junos.junos_config:
    confirm_commit: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: for idempotency, use full-form commands
  junipernetworks.junos.junos_config:
    lines:
      - set interfaces ge-0/0/1 unit 0 description "Test interface"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: configurable backup path
  junipernetworks.junos.junos_config:
    src: srx.cfg
    backup: true
    backup_options:
      filename: backup.cfg
      dir_path: /home/user
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set description with timer to confirm commit
  junipernetworks.junos.junos_config:
    lines:
      - set interfaces fxp0 description "wait for a commit confirmation for 3 minutes; otherwise, it will be rolled back."
    confirm: 3
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Perform confirm commit
  junipernetworks.junos.junos_config:
    confirm_commit: true

Inputs

    
src:
    description:
    - The I(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 I(lines) argument.
    type: path

lines:
    aliases:
    - commands
    description:
    - This argument takes a list of C(set) or C(delete) configuration lines to push into
      the remote device.  Each line must start with either C(set) or C(delete).  This
      argument is mutually exclusive with the I(src) argument.
    elements: str
    type: list

backup:
    default: false
    description:
    - This argument will cause the module to create a full backup of the current C(running-config)
      from the remote device before any changes are made. If the C(backup_options) value
      is not given, the backup file is written to the C(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.
    type: bool

update:
    choices:
    - merge
    - override
    - replace
    - update
    default: merge
    description:
    - This argument will decide how to load the configuration data particularly when the
      candidate configuration and loaded configuration contain conflicting statements.
      Following are accepted values. C(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. C(override) discards the entire candidate configuration and replaces
      it with the loaded configuration. C(replace) substitutes each hierarchy level in
      the loaded configuration for the corresponding level. C(update) is similar to the
      override option. The new configuration completely replaces the existing configuration.
      The difference comes when the configuration is later committed. This option performs
      a 'diff' between the new candidate configuration and the existing committed configuration.
      It then only notifies system processes responsible for the changed portions of the
      configuration, and only marks the actual configuration changes as 'changed'.
    type: str

comment:
    default: configured by junos_config
    description:
    - The C(comment) argument specifies a text string to be used when committing the configuration.  If
      the C(confirm) argument is set to False, this argument is silently ignored.
    type: str

confirm:
    default: 0
    description:
    - The C(confirm) argument will configure a time out value in minutes for the commit
      to be confirmed before it is automatically rolled back. If the value for this argument
      is set to 0, the commit is confirmed immediately which is also the default behaviour.
    type: int

replace:
    description:
    - The C(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 I(update) argument to C(replace). This argument will be removed in a future
      release. The C(replace) and C(update) argument is mutually exclusive.
    type: bool

zeroize:
    default: false
    description:
    - The C(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.
    type: bool

rollback:
    description:
    - The C(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 C(rollback) argument to 0.
    type: int

src_format:
    choices:
    - xml
    - set
    - text
    - json
    description:
    - The I(src_format) argument specifies the format of the configuration found int I(src).  If
      the I(src_format) argument is not provided, the module will attempt to determine
      the format of the configuration file specified in I(src).
    type: str

check_commit:
    default: false
    description:
    - This argument will check correctness of syntax; do not apply changes.
    - Note that this argument can be used to confirm verified configuration done via commit
      confirmed operation
    type: bool

backup_options:
    description:
    - This is a dict object containing configurable options related to backup file path.
      The value of this option is read only when C(backup) is set to I(true), if C(backup)
      is set to I(false) this option will be silently ignored.
    suboptions:
      backup_format:
        choices:
        - xml
        - set
        - text
        - json
        default: set
        description:
        - This argument specifies the format of the configuration the backup file will
          be stored as.  If the argument is not specified, the module will use the 'set'
          format.
        type: str
      dir_path:
        description:
        - This option provides the path ending with directory name in which the backup
          configuration file will be stored. If the directory does not exist it will be
          first created and the filename is either the value of C(filename) or default
          filename as described in C(filename) options description. If the path value
          is not given in that case a I(backup) directory will be created in the current
          working directory and backup configuration will be copied in C(filename) within
          I(backup) directory.
        type: path
      filename:
        description:
        - The filename to be used to store the backup configuration. If the filename is
          not given it will be generated based on the hostname, current time and date
          in format defined by <hostname>_config.<current-date>@<current-time>
        type: str
    type: dict

confirm_commit:
    default: false
    description:
    - This argument will execute commit operation on remote device. It can be used to
      confirm a previous commit.
    type: bool

Outputs

backup_path:
  description: The full path to the backup file
  returned: when backup is true
  sample: /playbooks/ansible/backup/config.2016-07-16@22:28:34
  type: str
date:
  description: The date extracted from the backup file name
  returned: when backup is true
  sample: '2016-07-16'
  type: str
filename:
  description: The name of the backup file
  returned: when backup is true and filename is not specified in backup options
  sample: junos01_config.2016-07-16@22:28:34
  type: str
shortname:
  description: The full path to the backup file excluding the timestamp
  returned: when backup is true and filename is not specified in backup options
  sample: /playbooks/ansible/backup/junos01_config
  type: str
time:
  description: The time extracted from the backup file name
  returned: when backup is true
  sample: '22:28:34'
  type: str