-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rescue function #7
base: devel
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,77 @@ | ||||||
# Save and Load rescue configuration into device | ||||||
|
||||||
The `config_manager/rescue` function provides a means to save a know good running configuration | ||||||
as a rescue configuration and rollback the current device configuration to rescue configuration | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
when required. | ||||||
|
||||||
## How to save a rescue configuration checkpoint | ||||||
|
||||||
Below is an example of how to call the `config_manager/rescue` function to mark the | ||||||
current running configuration as rescue config. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
``` | ||||||
- hosts: junos | ||||||
|
||||||
roles: | ||||||
- name: ansible-network.juniper_junos | ||||||
function: config_manager/resuce | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
config_manager_set_rescue: True | ||||||
``` | ||||||
|
||||||
### How to load the rescue configuration | ||||||
|
||||||
The `config_manager/rescue` function also provides support to rollback the current running | ||||||
configuration to a rescue configuration when required | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
In order to load the resuce configuration, the function as before but adds the | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
value `config_manager_load_rescue_config: yes` to the playbook to indicate that the configuration should | ||||||
be rollbacked to te the resuce configuration. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Note: Take caution when doing rescue configuration load that you do not | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
inadvertently replace your access to the device. | ||||||
|
||||||
``` | ||||||
- hosts: junos | ||||||
|
||||||
roles: | ||||||
- name: ansible-network.juniper_junos | ||||||
function: config_manager/resuce | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
config_manager_load_rescue_config: True | ||||||
``` | ||||||
|
||||||
## How to delete a rescue configuration checkpoint | ||||||
|
||||||
Below is an example of how to call the `config_manager/rescue` function to delete the | ||||||
previously set rescue configuration. | ||||||
|
||||||
``` | ||||||
- hosts: junos | ||||||
|
||||||
roles: | ||||||
- name: ansible-network.juniper_junos | ||||||
function: config_manager/resuce | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
config_manager_delete_rescue: True | ||||||
``` | ||||||
|
||||||
## Arguments | ||||||
|
||||||
### config_manager_set_rescue | ||||||
|
||||||
This setting indicates whether or not the to set the current running | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
configuration as the rescue configuration. | ||||||
|
||||||
The default value is `False` | ||||||
|
||||||
### config_manager_load_rescue_config | ||||||
|
||||||
This setting indicates whether or not to replace the current configuration | ||||||
with the rescue configuration. | ||||||
|
||||||
The default value is `False` | ||||||
|
||||||
### config_manager_delete_rescue | ||||||
|
||||||
This setting indicates whether or not the to delete the rescue configuration | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
checkpoint that is already set. | ||||||
|
||||||
The default value is `False` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||
--- | ||||||
argument_spec: | ||||||
ansible_network_os: | ||||||
description: | ||||||
- Set the name of the Ansible network OS platform. This value should be | ||||||
set to `junos` for this provider. | ||||||
required: true | ||||||
|
||||||
junos_config_set_rescue: | ||||||
descriptiion: | ||||||
- This setting indicates whether or not the to set the current running | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
configuration as the rescue configuration. | ||||||
type: bool | ||||||
default: False | ||||||
|
||||||
junos_config_load_rescue: | ||||||
descriptiion: | ||||||
- This setting indicates whether or not to replace the current configuration | ||||||
with the rescue configuration. | ||||||
type: bool | ||||||
default: False | ||||||
|
||||||
junos_config_delete_rescue: | ||||||
descriptiion: | ||||||
- This setting indicates whether or not the to delete the rescue configuration checkpoint that is already set. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
type: bool | ||||||
default: False |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
- name: initialize function | ||
include_tasks: includes/init.yaml | ||
|
||
- name: validate role spec | ||
validate_role_spec: | ||
spec: config_manager/rescue_spec.yaml | ||
|
||
- name: set current running configuration as rescue configuration | ||
cli: | ||
command: request system configuration rescue save | ||
when: junos_config_set_rescue | ||
|
||
- name: delete previously set rescue configuration | ||
cli: | ||
command: request system configuration rescue delete | ||
when: junos_config_delete_rescue | ||
|
||
- name: load rescue configuration | ||
block: | ||
- name: enter exclusive configuration mode | ||
cli: | ||
command: configure exclusive | ||
when: junos_configure_exclusive | ||
|
||
- name: enter configuration mode | ||
cli: | ||
command: configure | ||
when: not junos_configure_exclusive | ||
|
||
- name: load rescue configuration | ||
cli: | ||
command: "{{ line }}" | ||
loop: | ||
- rollback rescue | ||
- commit and-quit | ||
loop_control: | ||
loop_var: line | ||
when: junos_config_load_rescue_config |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ | |
|
||
- name: test replace function | ||
import_tasks: replace.yml | ||
|
||
- name: test replace function | ||
import_tasks: rescue.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
- debug: msg="START config_manager/rescue.yaml function on connection={{ ansible_connection }}" | ||
|
||
- name: ensure netconf is enabled | ||
junos_netconf: | ||
netconf_port: 22 | ||
|
||
- name: setup - remove syslog | ||
junos_config: &rm | ||
lines: | ||
- delete system syslog file test3 any any | ||
- delete system syslog file test4 any any | ||
connection: netconf | ||
|
||
- name: set rescue configuration | ||
include_role: | ||
name: "{{ juniper_junos_role_path }}" | ||
tasks_from: config_manager/rescue | ||
vars: | ||
config_manager_set_rescue: True | ||
|
||
- name: configure syslog | ||
junos_config: | ||
lines: | ||
- set system syslog file test3 any any | ||
- set system syslog file test4 any any | ||
connection: netconf | ||
|
||
- name: rollback to rescue configuration | ||
include_role: | ||
name: "{{ juniper_junos_role_path }}" | ||
tasks_from: config_manager/rescue | ||
vars: | ||
config_manager_load_rescue_config: True | ||
|
||
|
||
- name: fetch syslog configuration | ||
junos_command: | ||
commands: show configuration | display set | ||
register: show_config_result | ||
|
||
- assert: | ||
that: | ||
- "'set system syslog file test3 any any' not in show_config_result.stdout_lines[0]" | ||
- "'set system syslog file test4 any any' not in show_config_result.stdout_lines[0]" | ||
|
||
- name: teardown - remove rescue config | ||
include_role: | ||
name: "{{ juniper_junos_role_path }}" | ||
tasks_from: config_manager/rescue | ||
vars: | ||
config_manager_delete_rescue: True | ||
|
||
- name: teardown - remove syslog config | ||
junos_config: *rm | ||
connection: netconf | ||
|
||
- debug: msg="END config_manager/rescue.yaml replace function on connection={{ ansible_connection }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.