ansible/ansible-modules-core

Using junos_config to overwrite config does not work

hlantz opened this issue · 6 comments

ISSUE TYPE
  • Bug Report
COMPONENT NAME

junos_config module + module_utils/junos.py

ANSIBLE VERSION

ansible 2.2.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides

CONFIGURATION

Stock - no changes

OS / ENVIRONMENT

Running on Ubuntu 4.4.0.51, but should be platform independent.

SUMMARY

The junos_config module documentation does not allow for overwriting configuration (similar to the load override Junos CLI command). The module documentation states that using the replace: yes option will work, but is considered deprecated; and to use the update: replace option instead. However, neither of these keywords actually work - replace: yes lets the playbook run, but does not actually perform a load override but a load merge; and update: replace fails with an unknown parameter for the module. Digging in the module and module_utils code, it seems that the expected parameter to use is actually overwrite: yes, but this also fails with an unknown keyword. The module also does not seem to call the load_config function from the module_utils/junos.py with the correct arguments, causing load_config to default the overwrite variable to False on init.

In addition to this, it seems that the logic in the module_utils/junos.py resource file is wrong for the overwrite clause - it sets merge = True and overwrite = False; I'm guessing this should be the other way.

STEPS TO REPRODUCE

Run a playbook with the junos_config command to any Junos device. Include a complete config as the source and try various combinations of the parameters described above (replace: yes, update: replace and overwrite: yes). When running with replace: yes; I suggest attempting this against a switch, and trying to change the VLAN of an access port (the playbook will fail stating you can only have a single VLAN on an access port, since it's merging rather than replacing) or against a router changing an interface IP address (instead of replacing, the config will add a second IP to the interface in question). The other two cases above will fail with a parameter error.

- name: Push config to devices
  hosts: it-office-switches
  gather_facts: no
  tasks:
    - name: Installing config
      junos_config:
        host: "{{ junos_ip }}"
        port: 22
        username: "{{ junos_user }}"
        password: "{{ junos_password }}"
        update: replace
        comment: "Installing baseline config via Ansible"
        src: "{{ output_dir }}/config.conf"
        src_format: text
EXPECTED RESULTS

My goal was to push a config to a Junos device and have it apply it as if I ran a load override command.

ACTUAL RESULTS

Configuration is either merged with the existing config (similar to a load merge command) when running replace: yes or playbook fails completely when using update: replace or overwrite: yes.

@privateip, @gundalow, @Qalthos, @ganeshnalawade, ping. This issue is waiting on your response.
click here for bot help

@hlantz Overwrite and replace are two different actions as per junos documentation here. AFAIK currently only 'replace' is supported in 'junos_config' module.

@hlantz I have raised below PR's to add support for overwrite action.
ansible/ansible#19046
ansible/ansible#19038

Sample playbook snippet for this PR

      junos_config:
        host: "{{ inventory_hostname }}"
        src: basic/config.j2
        update: overwrite

@privateip @gundalow Please have a look at this PR.

@ganeshnalawade - Beautiful, thanks; this covers my needs!

Tested the patch provided by @ganeshnalawade - it seems to be working perfectly. Thanks!

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide.