Automation

 View Only
last person joined: yesterday 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  [Ansible] junos_get_config to get configuration with inheritance defaults values

    Posted 04-08-2019 09:33

    Hello,

     

    For an automation purpose, I'm trying to reproduce the following command in Ansible: show configuration | display xml | display inheritance defaults

     

    But I can't find a way to have the inheritance defaults values in the retrieved configuration. For the moment, this what I have, but it only do the command : show configuration | display xml

     

    - name: "GET CONF IN XML"
      junos_get_config:

        host: "{{ inventory_hostname }}"
        user: "{{ user }}"
        passwd: "{{ pass }}"
        format: xml
        dest: /playbooks/output/{{ inventory_hostname }}_conf.xml

     

    How could I modify this playbook or use another one to reproduice the command ?

    Any help will be appreciated

     

    Thanks


    #inheritancedefaults
    #Ansible
    #JUNOS


  • 2.  RE: [Ansible] junos_get_config to get configuration with inheritance defaults values
    Best Answer

     
    Posted 04-08-2019 18:01

    Hi NSI,

     

    The <inherit: "defaults"> option should do the trick for your use case. "To retrieve data from the post-inheritance configuration, which displays statements that are inherited from user-defined groups and ranges as children of the inheriting statements, you can include the options argument with inherit: "inherit" Now, if we check the <get-configuration> RPC, the "defaults" value for the inherit option is also present -

    https://www.juniper.net/documentation/en_US/junos/topics/reference/tag-summary/junos-xml-protocol-get-configuration.html

     

    This worked for me -

    ---
    - name: Get Configuration Inheritence Defaults
      hosts:
        - all
      roles:
        - Juniper.junos
      connection: local
      gather_facts: no
    
      vars_prompt:
        - name: username
          prompt: Junos Username
          private: no
    
        - name: password
          prompt: Junos Password
          private: yes
      tasks:
        - name: "Get = show configuration | display inheritence defaults | display xml"
          juniper_junos_config:
            retrieve: "committed"
            options:
              inherit: "defaults"
            provider:
              host: "{{ ansible_host }}"
              port: 22
              user: "{{ username }}"
              passwd: "{{ password }}"
            format: xml
            return_output: true

    Result:

    PLAYBOOK: config-inherit-defaults.yaml **************************************************************************************************************************************************************
    1 plays in config-inherit-defaults.yaml
    Junos Username: xxx
    Junos Password: 
    
    PLAY [Get Configuration Inheritence Defaults] *******************************************************************************************************************************************************
    META: ran handlers
    
    TASK [Get = show configuration | display inheritence defaults | display xml] ************************************************************************************************************************
    <...>
    ok: [sony] => {
        "changed": false, 
    "config_lines": [
    "<configuration commit-seconds=\"1173401135\" commit-localtime=\"2007-03-08 16:45:35 PST\" commit-user=xxx..",
            "    <version>16.1R6-S3.1</version>", 
            "    <comment>#", 
            "# Defines the default for dynamic-profiles", 
            "#</comment>", 
            "    <dynamic-profiles>", 
            "        <name>junos-default-profile</name>", 
            "        <variables>", 
            "            <name>junos-interface-unit</name>", 
            "            <undocumented><internal/></undocumented>", 
            "            <undocumented><valid-path>interface_unit_number|unit-number unit interface interface-set</valid-path></undocumented>", 
    <...>

    REF: Using Ansible to Retrieve or Compare Junos OS Configurations.

    ========================================

    Please mark this solution as "Accepted" if it works.

    Kudos are always appreciated as well 🙂

     

     

     

     



  • 3.  RE: [Ansible] junos_get_config to get configuration with inheritance defaults values

    Posted 04-10-2019 09:58

    Thanks for the quick answer ! It's working as I wanted !