Code Monkey home page Code Monkey logo

Comments (2)

spidercensus avatar spidercensus commented on July 20, 2024

Here's the docs on config loading via netconf:
http://www.juniper.net/documentation/en_US/junos13.2/topics/reference/tag-summary/netconf-junos-xml-protocol-load-configuration.html
We can enclose set statements in the following tags and pass them along:




I think in this case the config string included in the variable could actually have multiple set statements, as long as they were separated by newlines.

from ansible-junos-stdlib.

stacywsmith avatar stacywsmith commented on July 20, 2024

This is now supported in the new juniper_junos_config module via #290.

The new lines option can be used to specify configuration lines as in this example playbook:

---
- name: "Config from set lines"
  hosts: junos-all
  connection: local
  gather_facts: no
  roles:
    - Juniper.junos

  tasks:
    - name: Enable NETCONF SSH and traceoptions.
      juniper_junos_config:
        load: 'merge'
        lines:
          - 'set system services netconf ssh'
          - 'set system services netconf traceoptions flag all'
          - 'set system services netconf traceoptions file netconf.log'
        format: 'set'
        comment: 'Enable NETCONF with traceoptions'
      register: response
    - name: Print the complete response
      debug:
        var: response

Before the playbook is run, NETCONF over SSH is enabled, but traceoptions are not enabled:

user@r0> show configuration system services netconf 
ssh;

user@r0> 

The playbook is run:

user@h0:~$ ansible-playbook --limit r0 -k ./pb.test.yaml 
SSH password: 

PLAY [Config from set lines] *******************************************************************************************

TASK [Enable NETCONF SSH and traceoptions.] ****************************************************************************
changed: [r0]

TASK [Print the complete response] *************************************************************************************
ok: [r0] => {
    "response": {
        "changed": true, 
        "diff": "\n[edit system services netconf]\n+     traceoptions {\n+         file netconf.log;\n+         flag all;\n+     }\n", 
        "diff_lines": [
            "", 
            "[edit system services netconf]", 
            "+     traceoptions {", 
            "+         file netconf.log;", 
            "+         flag all;", 
            "+     }"
        ], 
        "failed": false, 
        "msg": "Configuration has been: opened, loaded, checked, diffed, committed, closed."
    }
}

PLAY RECAP *************************************************************************************************************
r0                         : ok=2    changed=1    unreachable=0    failed=0   

and new resulting configuration:

user@r0> show configuration system services netconf    
ssh;
traceoptions {
    file netconf.log;
    flag all;
}

user@r0>

The lines option takes a list of strings. However, the format is not restricted to set statements. It can be any supported config format, such as this example using a config in text format:

---
- name: "Config from text lines"
  hosts: junos-all
  connection: local
  gather_facts: no
  roles:
    - Juniper.junos

  tasks:
    - name: Replace NETCONF config with SSH only
      juniper_junos_config:
        load: 'replace'
        lines:
          - 'system {'
          - '    services {'
          - '        replace: netconf {'
          - '            ssh;'
          - '        }'
          - '    }'
          - '}'
        format: 'text'
        comment: 'Replace NETCONF config with SSH only'
      register: response
    - name: Print the complete response
      debug:
        var: response

Executing this playbook:

user@h0:~$ ansible-playbook --limit r0 -k ./pb.test.yaml 
SSH password: 

PLAY [Config from text lines] ******************************************************************************************

TASK [Replace NETCONF config with SSH only] ****************************************************************************
changed: [r0]

TASK [Print the complete response] *************************************************************************************
ok: [r0] => {
    "response": {
        "changed": true, 
        "diff": "\n[edit system services netconf]\n-     traceoptions {\n-         file netconf.log;\n-         flag all;\n-     }\n", 
        "diff_lines": [
            "", 
            "[edit system services netconf]", 
            "-     traceoptions {", 
            "-         file netconf.log;", 
            "-         flag all;", 
            "-     }"
        ], 
        "failed": false, 
        "msg": "Configuration has been: opened, loaded, checked, diffed, committed, closed."
    }
}

PLAY RECAP *************************************************************************************************************
r0                         : ok=2    changed=1    unreachable=0    failed=0   

Using the lines option to load configs in xml or json formats is also supported, but I'll leave that as an exercise for the reader.

from ansible-junos-stdlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.