Juniper.junos Ansible Modules

Contents:

junos_rollback - Rollback configuration of device

Author:Rick Sherman, Juniper Networks

Synopsis

New in version 1.2.0.

Rollback the configuration of a device running Junos

Options

parameter required default choices comments
comment no None
    Provide a comment to the commit of the configuration
    confirm no None
      Provide a confirm in minutes to the commit of the configuration
      diffs_file no None
        Path to the file where any diffs will be written
        host yes
          Set to {{ inventory_hostname }}
          logfile no None
            Path on the local server where the progress status is logged for debugging purposes
            passwd no assumes ssh-key active
              Login password
              port no 830
                TCP port number to use when connecting to the device
                rollback yes None
                  The rollback id value [0-49]
                  user no $USER
                    Login username

                    Note

                    Requires junos-eznc >= 1.2.2

                    Examples


                    - junos_rollback:
                       host: "{{ inventory_hostname }}"
                       logfile=rollback.log
                       diffs_file=rollback.diff
                       rollback=1
                       comment="Rolled back by Ansible"
                       confirm=5
                    

                    junos_install_os - Install a Junos OS image.

                    Author:Jeremy Schulman, Juniper Networks

                    Synopsis

                    New in version 1.0.0.

                    Install a Junos OS image on one or more Routing Engines. This module supports installations on single Routing Engine devices, MX Series routers with dual Routing Engines, and EX Series switches in a non-mixed Virtual Chassis. This action is equivalent to performing the Junos OS request system software add operational command. If the existing Junos OS version matches the desired version, no action is performed, and the “changed” attribute reports False. If the existing version does not match, then the module performs the following actions (1) Computes the MD5 checksum of the package located on the server. (2) Copies the Junos OS software package to the device running Junos OS. (3) Computes the MD5 checksum on the device running Junos OS and compares the two. (4) Installs the Junos OS software package. (5) Reboots the device (default). Running the module in check mode reports whether the current Junos OS version matches the desired version.

                    Options

                    parameter required default choices comments
                    host yes
                      Set to {{ inventory_hostname }}
                      logfile no None
                        Path on the local server where the progress status is logged for debugging purposes
                        no_copy no
                        • true
                        • false
                        Installer need to be copied or not on the device.
                        package yes
                          Absolute path on the local server to the Junos OS software package
                          passwd no assumes ssh-key active
                            Login password
                            port no 830
                              TCP port number to use when connecting to the device
                              reboot no True
                              • yes
                              • no
                              If set to yes, the device reboots after the installation completes.
                              reboot_pause no 10
                                Amount of time in seconds to wait after the reboot is issued
                                user no $USER
                                  Login username
                                  version yes
                                    Junos OS version string as it would be reported by the show version command

                                    Note

                                    Requires py-junos-eznc >= 1.2.2

                                    Examples


                                    - junos_install_os:
                                        host={{ inventory_hostname }}
                                        version=12.1X46-D10.2
                                        package=/usr/local/junos/images/junos-vsrx-12.1X46-D10.2-domestic.tgz
                                        logfile=/usr/local/junos/log/software.log
                                    

                                    junos_commit - Execute commit on device

                                    Author:Rick Sherman, Juniper Networks

                                    Synopsis

                                    New in version 1.2.0.

                                    Execute a Commit on a device running Junos independently of loading a configuration

                                    Options

                                    parameter required default choices comments
                                    comment no None
                                      Provide a comment to the commit of the configuration
                                      confirm no None
                                        Provide a confirm in minutes to the commit of the configuration
                                        host yes
                                          Set to {{ inventory_hostname }}
                                          logfile no None
                                            Path on the local server where the progress status is logged for debugging purposes
                                            passwd no assumes ssh-key active
                                              Login password
                                              port no 830
                                                TCP port number to use when connecting to the device
                                                timeout no 0
                                                  Extend the NETCONF RPC timeout beyond the default value of 30 seconds. Set this value to accommodate commits that might take longer than the default timeout interval.
                                                  user no $USER
                                                    Login username

                                                    Note

                                                    Requires junos-eznc >= 1.2.2

                                                    Examples


                                                    - junos_commit:
                                                       host: "{{ inventory_hostname }}"
                                                       logfile=changes.log
                                                       comment="Non load commit"
                                                    

                                                    junos_get_config - Retrieve configuration of device

                                                    Author:Rick Sherman, Juniper Networks

                                                    Synopsis

                                                    New in version 1.2.0.

                                                    Retrieve the configuration of a device running Junos and save it to a file. Note unicode chars will be converted to ‘??’ as also done in PyEZ

                                                    Options

                                                    parameter required default choices comments
                                                    dest yes None
                                                      Path to the local server directory where configuration will be saved.
                                                      filter no None
                                                        Defines heircachy of configuration to retrieve. If omitted entire configuration is retrieved. Format is slash notation ex groups/routeinst/routing-instances/ISP-1
                                                        format no text
                                                        • text
                                                        • xml
                                                        text - configuration saved as text (curly-brace) formatxml - configuration saved as XML
                                                        host yes
                                                          Set to {{ inventory_hostname }}
                                                          logfile no None
                                                            Path on the local server where the progress status is logged for debugging purposes
                                                            options no None
                                                              Additional options to pass to get_config. Refer to jnpr.junos.rpcmeta.get_config for details.
                                                              passwd no assumes ssh-key active
                                                                Login password
                                                                port no 830
                                                                  TCP port number to use when connecting to the device
                                                                  user no $USER
                                                                    Login username

                                                                    Note

                                                                    Requires junos-eznc >= 1.2.2

                                                                    Examples


                                                                    - junos_get_config:
                                                                       host: "{{ inventory_hostname }}"
                                                                       logfile: get_config.log
                                                                       dest: "{{ inventory_hostname }}.xml"
                                                                       format: xml
                                                                       filter: "interfaces"
                                                                       options: {inherit: inherit, groups: groups}
                                                                    

                                                                    junos_shutdown - Shut down or reboot a device running Junos OS.

                                                                    Author:Jeremy Schulman, Juniper Networks

                                                                    Synopsis

                                                                    New in version 1.0.0.

                                                                    Shut down (power off) or reboot a device running Junos OS. This includes all Routing Engines in a Virtual Chassis or a dual Routing Engine system. This is equivalent to executing either the Junos OS request system power-off or request system reboot operational command.

                                                                    Options

                                                                    parameter required default choices comments
                                                                    host yes
                                                                      Set to {{ inventory_hostname }}
                                                                      passwd no assumes ssh-key active
                                                                        Login password
                                                                        port no 830
                                                                          TCP port number to use when connecting to the device
                                                                          reboot no
                                                                          • yes
                                                                          • no
                                                                          If set to yes, then the device is rebooted rather than powered off.
                                                                          shutdown yes None
                                                                            Safety mechanism. You MUST set this to 'shutdown'.
                                                                            user no $USER
                                                                              Login username

                                                                              Note

                                                                              Requires junos-eznc >= 1.2.2

                                                                              Examples


                                                                              - junos_shutdown:
                                                                                  host={{ inventory_hostname }}
                                                                                  shutdown="shutdown"
                                                                                  reboot=yes
                                                                              

                                                                              junos_get_facts - Retrieve facts for a device running Junos OS.

                                                                              Author:Jeremy Schulman, Juniper Networks

                                                                              Synopsis

                                                                              New in version 1.0.0.

                                                                              Retrieve facts for a device running Junos OS, which includes information such as the serial number, product model, and Junos OS version. The module supports using both NETCONF and CONSOLE-based retrieval and returns the information as a JSON dictionary. The information is similar to facts gathered by other IT frameworks.

                                                                              Options

                                                                              parameter required default choices comments
                                                                              console no None
                                                                                CONSOLE port, per the netconify utility
                                                                                host yes
                                                                                  Set to {{ inventory_hostname }}
                                                                                  logfile no None
                                                                                    Path on the local server where the progress status is logged for debugging purposes. This option is used only with the console option.
                                                                                    passwd no assumes ssh-key active
                                                                                      Login password
                                                                                      port no 830
                                                                                        TCP port number to use when connecting to the device
                                                                                        savedir no $CWD
                                                                                          Path to the local server directory where device fact files will be stored. Resulting file will be savedir/hostname-facts.json
                                                                                          user no $USER
                                                                                            Login username

                                                                                            Note

                                                                                            Requires junos-eznc >= 1.2.2

                                                                                            Note

                                                                                            Requires junos-netconify >= 1.0.1, when using the console option

                                                                                            Examples


                                                                                            # retrieve facts using NETCONF, assumes ssh-keys
                                                                                            
                                                                                            - junos_get_facts: host={{ inventory_hostname }}
                                                                                              register: junos
                                                                                            
                                                                                            # retrieve facts using CONSOLE, assumes Amnesiac system
                                                                                            # root login, no password
                                                                                            
                                                                                            - junos_get_facts:
                                                                                                host={{ inventory_hostname }}
                                                                                                user=root
                                                                                                console="--telnet={{TERMSERV}},{{TERMSERVPORT}}"
                                                                                                savedir=/usr/local/junos/inventory
                                                                                              register: junos
                                                                                            
                                                                                            # access the facts
                                                                                            
                                                                                            - name: version
                                                                                              debug: msg="{{ junos.facts.version }}"
                                                                                            

                                                                                            junos_rpc - run given rpc

                                                                                            Author:Nitin Kumar, Juniper Networks

                                                                                            Synopsis

                                                                                            New in version 1.9.

                                                                                            run given rpc

                                                                                            Options

                                                                                            parameter required default choices comments
                                                                                            dest no None
                                                                                              Path to the local server directory where configuration will be saved.
                                                                                              filter_xml no
                                                                                                This options can be used with get-config rpc only, to retrieve specific config
                                                                                                format no xml
                                                                                                • text
                                                                                                • xml
                                                                                                text - configuration saved as text (curly-brace) formatxml - configuration saved as XML
                                                                                                host yes
                                                                                                  Set to {{ inventory_hostname }}
                                                                                                  kwargs no
                                                                                                    params need to be passed to rpc kwargs="interface_name=em0" or kwargs="interface_name=em0,media=True" kwargs={interface_name:em0} kwargs={interface_name:em0,media:True}
                                                                                                    logfile no None
                                                                                                      Path on the local server where the progress status is logged for debugging purposes. This option is used only with the console option.
                                                                                                      passwd no assumes ssh-key active
                                                                                                        Login password
                                                                                                        rpc no
                                                                                                          rpc to be executed
                                                                                                          user no $USER
                                                                                                            Login username

                                                                                                            Note

                                                                                                            Requires junos-eznc >= 1.0.0

                                                                                                            Examples


                                                                                                            # retrieve rpc response using NETCONF
                                                                                                            
                                                                                                            - junos_rpc:
                                                                                                              host={{ inventory_hostname }}
                                                                                                              rpc=get-interface-information
                                                                                                              dest=get_interface_information.conf
                                                                                                              register=junos
                                                                                                            
                                                                                                            - junos_rpc:
                                                                                                              host={{ inventory_hostname }}
                                                                                                              rpc=get-interface-information
                                                                                                              kwargs="interface_name=em0"
                                                                                                              format=xml/text/json
                                                                                                              dest=get_interface_information.conf
                                                                                                              register=junos
                                                                                                            
                                                                                                            # print the config
                                                                                                            - name: version
                                                                                                              debug: msg="{{ junos.rpc_reply }}"
                                                                                                            
                                                                                                            # Example to fetch device configuration
                                                                                                            - name: Get Device Configuration
                                                                                                              junos_rpc:
                                                                                                                host={{ inventory_hostname }}
                                                                                                                rpc=get-config
                                                                                                                dest=get_config.conf
                                                                                                            
                                                                                                            # Example to fetch device configuration
                                                                                                            - name: Get Device Configuration for interface
                                                                                                              junos_rpc:
                                                                                                                host={{ inventory_hostname }}
                                                                                                                rpc=get-config
                                                                                                                filter_xml="<configuration><interfaces/></configuration>"
                                                                                                                dest=get_config.conf
                                                                                                              register: junos
                                                                                                            

                                                                                                            junos_srx_cluster - Create an srx chassis cluster for cluster capable srx running Junos OS.

                                                                                                            Author:Patrik Bok, Ashley Burston, Rick Sherman, Juniper Networks

                                                                                                            Synopsis

                                                                                                            New in version 1.2.0.

                                                                                                            Create an srx chassis cluster and reboot the device. The device must be capable of forming an srx cluster and have the correct cables installed.

                                                                                                            Options

                                                                                                            parameter required default choices comments
                                                                                                            cluster_enable yes
                                                                                                            • true
                                                                                                            • false
                                                                                                            • yes
                                                                                                            • no
                                                                                                            yes/true - set device to cluster mode (specify cluster_id and node)no/false - set device to stand alone mode (disable cluster mode)
                                                                                                            cluster_id no None
                                                                                                              set to the cluster id , required for cluster_enable=YES
                                                                                                              console no None
                                                                                                                SERIAL or TERMINAL-SERVER port setting, per use with the netconify utility
                                                                                                                host yes
                                                                                                                  Set to {{ inventory_hostname }}
                                                                                                                  logfile no None
                                                                                                                    Path on the local server where the progress status is logged for debugging purposes
                                                                                                                    node no None
                                                                                                                      set to the node required (0 or 1)
                                                                                                                      passwd no assumes ssh-key active
                                                                                                                        Login password
                                                                                                                        port no 830
                                                                                                                          TCP port number to use when connecting to the device
                                                                                                                          user no $USER
                                                                                                                            Login username

                                                                                                                            Note

                                                                                                                            Requires junos-eznc >= 1.2.2

                                                                                                                            Examples


                                                                                                                            -junos_srx_cluster:
                                                                                                                              host={{ inventory_hostname }}
                                                                                                                              console="--port={{ serial }}"
                                                                                                                              user=rick
                                                                                                                              passwd=password123
                                                                                                                              cluster_enable=true
                                                                                                                              logfile=cluster.log
                                                                                                                              cluster_id={{ cluster_id }}
                                                                                                                              node={{ node_id }}
                                                                                                                            
                                                                                                                            -junos_srx_cluster:
                                                                                                                              host={{ inventory_hostname }}
                                                                                                                              user=rick
                                                                                                                              passwd=password123
                                                                                                                              cluster_enable=false
                                                                                                                              logfile=cluster.log
                                                                                                                            

                                                                                                                            junos_zeroize - Erase all data, including configuration and log files, on a device running Junos OS.

                                                                                                                            Author:Jeremy Schulman, Juniper Networks

                                                                                                                            Synopsis

                                                                                                                            New in version 1.0.0.

                                                                                                                            Execute the Junos OS request system zeroize command to remove all configuration information on the Routing Engines and reset all key values on a device running Junos OS. The command removes all data files, including customized configuration and log files, by unlinking the files from their directories. The command also removes all user-created files from the system including all plain-text passwords, secrets, and private keys for SSH, local encryption, local authentication, IPsec, RADIUS, TACACS+, and SNMP. This command reboots the device and sets it to the factory default configuration. After the reboot, you must log in through the console as root in order to access the device.

                                                                                                                            Options

                                                                                                                            parameter required default choices comments
                                                                                                                            console no None
                                                                                                                              SERIAL or TERMINAL-SERVER port setting, per use with the netconify utility
                                                                                                                              host no
                                                                                                                                Set to {{ inventory_hostname }}
                                                                                                                                logfile no None
                                                                                                                                  Path on the local server where the progress status is logged for debugging purposes
                                                                                                                                  passwd no assumes ssh-key active
                                                                                                                                    Login password
                                                                                                                                    port no 830
                                                                                                                                      TCP port number to use when connecting to the device
                                                                                                                                      user no $USER
                                                                                                                                        Login username
                                                                                                                                        zeroize yes None
                                                                                                                                          Safety mechanism. You MUST set this to 'zeroize'.

                                                                                                                                          Note

                                                                                                                                          Requires junos-eznc >= 1.2.2

                                                                                                                                          Note

                                                                                                                                          Requires junos-netconify >= 1.0.1, when using the console option

                                                                                                                                          Examples


                                                                                                                                          - junos_zeroize:
                                                                                                                                              host={{ inventory_hostname }}
                                                                                                                                              zeroize="zeroize"
                                                                                                                                          

                                                                                                                                          Note

                                                                                                                                          You MUST either use the host option or the console option to designate how the device is accessed.

                                                                                                                                          junos_cli - Execute CLI on device and save the output locally

                                                                                                                                          Author:Damien Garros, Juniper Networks

                                                                                                                                          Synopsis

                                                                                                                                          New in version 1.2.0.

                                                                                                                                          Execute CLI on device and save the output locally on a file

                                                                                                                                          Options

                                                                                                                                          parameter required default choices comments
                                                                                                                                          cli yes
                                                                                                                                            CLI command to execute on the host
                                                                                                                                            dest yes None
                                                                                                                                              Path to the local server directory where cli output will be saved.
                                                                                                                                              format no text
                                                                                                                                              • text
                                                                                                                                              • xml
                                                                                                                                              text - Cli output saved in text formatxml - Cli output saved as XML
                                                                                                                                              host yes
                                                                                                                                                Set to {{ inventory_hostname }}
                                                                                                                                                logfile no None
                                                                                                                                                  Path on the local server where the progress status is logged for debugging purposes
                                                                                                                                                  passwd no assumes ssh-key active
                                                                                                                                                    Login password
                                                                                                                                                    port no 830
                                                                                                                                                      TCP port number to use when connecting to the device
                                                                                                                                                      user no $USER
                                                                                                                                                        Login username

                                                                                                                                                        Note

                                                                                                                                                        Requires junos-eznc >= 1.2.2

                                                                                                                                                        Examples


                                                                                                                                                        - junos_cli:
                                                                                                                                                           host: "{{ inventory_hostname }}"
                                                                                                                                                           cli: "show chassis hardware"
                                                                                                                                                           logfile: cli.log
                                                                                                                                                           dest: "{{ inventory_hostname }}.xml"
                                                                                                                                                           format: xml
                                                                                                                                                        

                                                                                                                                                        junos_install_config - Load a configuration file or snippet onto a device running Junos OS.

                                                                                                                                                        Author:Jeremy Schulman, Juniper Networks

                                                                                                                                                        Synopsis

                                                                                                                                                        New in version 1.0.0.

                                                                                                                                                        Load a complete Junos OS configuration (overwrite) or merge a configuration snippet onto a device running Junos OS and commit it. The default behavior is to perform a load merge operation (overwrite=’no’). This module performs an atomic lock/edit/unlock. If the process fails at any step, then all configuration changes are discarded. You can load the configuration using either NETCONF or the CONSOLE port. Specify the console option to use the CONSOLE port. You provide the configuration data in a file. Supported formats when using NETCONF include ASCII text, Junos XML elements, and Junos OS set commands. Configurations performed through the console must only use ASCII text formatting.

                                                                                                                                                        Options

                                                                                                                                                        parameter required default choices comments
                                                                                                                                                        comment no None
                                                                                                                                                          Provide a comment to the commit of the configuration
                                                                                                                                                          confirm no None
                                                                                                                                                            Provide a confirm in minutes to the commit of the configuration
                                                                                                                                                            console no None
                                                                                                                                                              Port configuration, per the netconify utility
                                                                                                                                                              diffs_file no None
                                                                                                                                                                Path to the file where any diffs will be written
                                                                                                                                                                file yes
                                                                                                                                                                  Path to the file containing the Junos OS configuration data. If the file has a *.conf extension, the content is treated as text format. If the file has a *.xml extension, the content is treated as XML format. If the file has a *.set extension, the content is treated as Junos OS set commands.
                                                                                                                                                                  host yes
                                                                                                                                                                    Set to {{ inventory_hostname }}
                                                                                                                                                                    logfile no None
                                                                                                                                                                      Path on the local server where the progress status is logged for debugging purposes
                                                                                                                                                                      overwrite no
                                                                                                                                                                      • true
                                                                                                                                                                      • false
                                                                                                                                                                      • yes
                                                                                                                                                                      • no
                                                                                                                                                                      Specify whether the configuration file completely replaces the existing configuration.
                                                                                                                                                                      passwd no assumes ssh-key active
                                                                                                                                                                        Login password
                                                                                                                                                                        port no 830
                                                                                                                                                                          TCP port number to use when connecting to the device
                                                                                                                                                                          replace no
                                                                                                                                                                          • true
                                                                                                                                                                          • false
                                                                                                                                                                          • yes
                                                                                                                                                                          • no
                                                                                                                                                                          Specify whether the configuration file uses "replace:" statements. (NETCONF only) NOT compatible with set format
                                                                                                                                                                          savedir no None
                                                                                                                                                                            Path to the local server directory where device facts and inventory files will be stored. This option is used only with the console option. Refer to the netconify utility for details.
                                                                                                                                                                            timeout no 0
                                                                                                                                                                              Extend the NETCONF RPC timeout beyond the default value of 30 seconds. Set this value to accommodate configuration changes (commits) that might take longer than the default timeout interval.
                                                                                                                                                                              user no $USER
                                                                                                                                                                                Login username

                                                                                                                                                                                Note

                                                                                                                                                                                Requires junos-eznc >= 1.2.2

                                                                                                                                                                                Note

                                                                                                                                                                                Requires junos-netconify >= 1.0.1, when using the console option

                                                                                                                                                                                Examples


                                                                                                                                                                                # load merge a change to the Junos OS configuration using NETCONF
                                                                                                                                                                                
                                                                                                                                                                                - junos_install_config:
                                                                                                                                                                                    host={{ inventory_hostname }}
                                                                                                                                                                                    file=banner.conf
                                                                                                                                                                                
                                                                                                                                                                                # load overwrite a new Junos OS configuration using the CONSOLE port
                                                                                                                                                                                
                                                                                                                                                                                - junos_install_config:
                                                                                                                                                                                    host={{ inventory_hostname }}
                                                                                                                                                                                    console="--telnet={{TERMSERV}},{{TERMSERV_PORT}}"
                                                                                                                                                                                    file=default_new_switch.conf
                                                                                                                                                                                    overwrite=yes
                                                                                                                                                                                
                                                                                                                                                                                # load merge a change to the Junos OS configuration using NETCONF and supplying a commit log message
                                                                                                                                                                                - junos_install_config:
                                                                                                                                                                                    host={{ inventory_hostname }}
                                                                                                                                                                                    file=banner.conf
                                                                                                                                                                                    comment="configured by ansible"
                                                                                                                                                                                
                                                                                                                                                                                # load replace a change to the Junos OS configuration using NETCONF
                                                                                                                                                                                - junos_install_config:
                                                                                                                                                                                    host={{ inventory_hostname }}
                                                                                                                                                                                    file=snmp.conf
                                                                                                                                                                                    replace=yes