/
ios_show_lab_brief.yml
72 lines (62 loc) · 2.72 KB
/
ios_show_lab_brief.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
---
###############################################################################
# This playbook utilizes the ios_command ansible module to execute a set of
# show commands against the cisco ios devices defined in the [cisco_xe]
# group within the hosts file. The command iterates over a list of show commands
# and saves the result of each command into the output variable.
#
# The output variable is then displayed as part of the playbook run
#
# The contents of the output variable are then saved using two different methods.
# device-output.txt has the raw output format which is a JSON data structure
# device.cfg saves the results of the first command sent which in this case
# is the show run command (hence the .cfg file type)
#
# The final play uses the templates module to save the show command output in the
# more traditional text based output.
#
# The resulting output files are saved in the ./logs directory
#
# This version only includes show commands that will likely work.
#
# EXECUTION:
# ansible-playbook -i hosts ios_show_lab_brief.yml
###############################################################################
- name: Pull show commands form Cisco IOS_XE Always On Sandbox device
hosts: cisco_xe
gather_facts: False
ignore_errors: yes
# The commented lines show the pre Ansible 2.5 method of passing credentials to network modules using the "provider"
# method. In Ansible 2.5 the network_cli connection method was introduced in order to better align network
# and server modules so they behave in a more consistent manner.
# connection: local
# vars:
# cli:
# host: "{{ inventory_hostname }}"
# username: "{{ ansible_user }}"
# password: "{{ ansible_password }}"
# port: "{{ ansible_port }}"
# timeout: 30
tasks:
- name: Iterate over show commands
ios_command:
commands: "{{ item }}"
# provider: "{{ cli }}"
with_items:
- "show run"
- "show version"
- "show inventory"
- "show ip int br"
- "show ip route"
register: output
- debug: var=output
# Save the raw output which is an unformatted data structure
- local_action: copy content="{{ output.results }}" dest="./logs/{{ inventory_hostname }}-raw-output.txt"
# Sae the configuration only in the commonly formatted file
- local_action: copy content="{{ output.results.0.stdout.0 }}" dest="./logs/{{ inventory_hostname }}-config.txt"
# Run the output through a Jinja2 template to get all the show commands in their common format
- name: Generate Device Show Command File(s)
template: src=./templates/show-commands-template.j2
dest=./logs/{{ inventory_hostname }}-readable-show-output.txt
with_items:
- "{{ output }}"