-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_config.yml
103 lines (93 loc) · 3.95 KB
/
push_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
- name: NetIM Full and Section Rollback Playbook
hosts: all
gather_facts: no
vars:
full_section: "{{ full_rollback }}"
# Remember to run a playbook command line and pass arguments, looks something like this
# ansible-playbook main-command-line.yml --extra-var "dev_name=15027 device_archive_file_path=/api/netim/v1/archives/282059/file"
tasks:
- name: NetIM Full Rollback Request Debug message
when:
- "'NetIMGroup' in group_names"
- "full_section == 'Full'"
debug:
msg:
- "NetIM Requested a Rollback for {{ dev_name }}, will retrieve the previous config file"
- "from this NetIM path {{device_archive_file_path}}"
- name: Retrieve Full Rollback Config File from NetIM (to NetIM REST API)
when:
- "'NetIMGroup' in group_names"
- "full_section == 'Full'"
debug:
msg: "Retrieved previous config file from NetIM for {{ dev_name }}"
- name: Access NetIM REST API to retrieve Full config file
when:
- "'NetIMGroup' in group_names"
- "full_section == 'Full'"
uri:
# deviced_archive_file_path looks like this '/api/netim/v1/archives/281533/file'
url: "https://10.1.150.232:8543 {{device_archive_file_path}} "
method: GET
url_username: scadmin
url_password: R3st0nVA
force_basic_auth: yes
validate_certs: no
# This forces content to be returned, if not specified and JSON is present, then JSON will be returned
return_content: yes
status_code: 200
# This writes the output to a file named 'config.txt
# Since this AWX and Docker, the actual location is in a Docker folder somewhere..
dest: ./config_orig.txt
# Ansible uses register to specify a variable name and it is implicit to the output of the uri:
# Notice it is NOT indented, at same indent level as uri:
register: rest_get
# This is debug test to see the config file text on the Ansible console screen
- name: Config file debug output for Full Rollback
when:
- "'NetIMGroup' in group_names"
- "full_section == 'Full'"
debug:
msg: "The output of the config file is {{lookup('file', './config_orig.txt') }}"
# I got frustrated trying to read in the file and parse with Ansible so cheating with Python..
- name: Remove some lines from the config file (header and footer)
when:
- "'NetIMGroup' in group_names"
- "full_section == 'Full'"
script: "/usr/bin/python3 config_strip.py"
- name: Display the scrubbed output of the config file
when:
- "'NetIMGroup' in group_names"
- "full_section == 'Full'"
debug:
msg: "The scrubbed output of the config file is {{lookup('file', './config_scrubbed.txt') }}"
######## Only for Cisco host ##########
- name: Install Section Rollback Config and save diff
when:
- "'CiscoPush' in group_names"
- "full_section == 'Section'"
napalm_install_config:
hostname: '{{ inventory_hostname }}'
username: admin
password: riverbed
# optional_args: {'secret': 'riverbed', 'inline_transfer': 'True'}
optional_args: {'secret': 'riverbed', 'inline_transfer': 'True', 'global_delay_factor': 4, 'session_log':'/tmp/{{ inventory_hostname}}_napalm.log'}
dev_os: ios
config_file: '/tmp/config_merge_file.txt'
# config_file: '/home/centos/flask/config_merge_file.txt'
replace_config: 'False'
commit_changes: 'True'
archive_file: 'True'
get_diffs: 'True'
diff_file: 'diff.txt'
- name: Read Cisco IOS running-config
when: "'Cisco-Push' in group_names"
ios_config:
backup: yes
backup_options:
filename: Mid-backup.txt
register: backup_contents
- name: Output running config to screen
when: "'Cisco-Push' in group_names"
debug:
msg: "The contents of the rolled-back config file are {{ lookup('file','backup/Mid-backup.txt') }} "