Last active
December 14, 2020 08:20
-
-
Save NWMichl/324f87e4e4cd8b03da2457496374e9c3 to your computer and use it in GitHub Desktop.
A declarative Ansible playbook to manage Cisco NX-OS syslog server configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Syslog configuration with Cisco NX-OS devices | |
# | |
# Usage: ansible-playbook -k -u <cli_user> syslog_nxos.yml | |
# Specify the syslog servers in the 'vars:' section of the playbook header. | |
--- | |
- name: Ensure desired state - syslog server | |
hosts: all | |
gather_facts: false | |
connection: network_cli | |
vars: | |
syslog_vrf: management | |
syslog_sev: 6 | |
syslog_server: | |
- 192.0.2.1 | |
- 192.0.2.10 | |
tasks: | |
- name: GATHER RUNNING CONFIG REGARDING SYSLOG SERVERS | |
nxos_command: | |
commands: show run | incl "logging server" | |
register: run_config_syslog | |
when: ansible_network_os == 'nxos' | |
- name: PARSE LIST OF CONFIGURED SYSLOG SERVERS | |
set_fact: | |
configured_syslogserver: "{{ run_config_syslog.stdout[0] | regex_findall('\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b') }}" | |
when: ansible_network_os == 'nxos' | |
- name: CONFIGURE SYSLOG SERVERS | |
nxos_config: | |
lines: | |
- logging server {{ item }} {{ syslog_sev | default (5) }} use-vrf {{ syslog_vrf | default ('default') }} | |
save_when: changed | |
loop: "{{ syslog_server }}" | |
when: ansible_network_os == 'nxos' | |
- name: DELETE ORPHAN SYSLOG SERVERS | |
nxos_config: | |
lines: | |
- no logging server {{ item }} | |
save_when: changed | |
loop: "{{ configured_syslogserver }}" | |
when: ansible_network_os == 'nxos' and item not in syslog_server | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment