Ansible4Networking Newsletter
Tony Dubiel
Principal Specialist Solution Architect - NAPS | Ansible Networking - Red Hat | 3xCCIE
Welcome to the Ansible4Networking monthly newsletter!
Please subscribe to this newsletter to keep up to date with the latest developments in network automation and related events. Each newsletter will provide news on the latest features and emerging topics as well as a short Ansible tutorial. This month we will look at Ansible Lightspeed developments and switch gears to the set_stats module for a tutorial.
News:
Ansible Lightspeed with IBM Watson Code Assistant is AI that is purpose-built and applied for IT automation.
Technically Speaking features captivating conversations between Chris Wright and a rotating cast of experts and industry leaders around what's on the horizon for technology.
Lightspeed Checkout an overview of Lightspeed on Red Hat Technically Speaking with Chris Wright
Learn more about Ansible Lightspeed:
Ansible Tutorial: Artifacts and set_stats
The?set_stats?module stores variable "facts" from running a playbook/job-template job in the Automation Controller database. In turn, you are then able to pass state information "artifacts" between other playbooks / job templates in the same workflow.
Scenario: The following workflow will do the following:
AAP 2.4 Workflow:
This playbook "copy_config.yml" will be the first node in a the "Ansible4Networking_set_stats" Workflow. Please see the usage of the set_stats module below:
领英推荐
---
- name: Copy router configs and make Artifact for future (job-template) playbooks
hosts: rtr1
gather_facts: False
tasks:
- name: Copy router configs
cisco.ios.ios_config:
backup: true
backup_options:
filename: "{{inventory_hostname}}.cfg"
dir_path: /tmp/backups
register: config_output
- name: remove non config lines - regexp
ansible.builtin.lineinfile:
path: "{{ config_output.backup_path }}"
line: "Building configuration..."
state: absent
delegate_to: localhost
- name: Cat Configs
ansible.builtin.shell:
cmd: "cat /tmp/backups/{{inventory_hostname}}.cfg"
register: backups
- name: Artifact of Config Files
ansible.builtin.set_stats:
data:
configs: "{{ backups.stdout }}"
This playbook "make_change.yml" is the next node in the workflow. A self service "survey" is used to populate the "{{ description }}" variable.
--
- name: Make a quick change
hosts: rtr1
gather_facts: False
tasks:
- name: Merge provided configuration with device configuration
cisco.ios.ios_interfaces:
config:
- name: Loopback0
description: "{{ description }}"-
This playbook "read_stats.yml" is the final node in the workflow. As you recall, the configs variable was defined and saved by set_stats in the first node of the workflow. Effectively, the artifact of the router config was passed from one playbook to another so we could compare the DIFF of the running and intended configuration. In this example we made a router change on purpose but the diff would also identify any unintended changes from the backup "intended" config .
---
- name: Read in Artifact of router configs to compare (diff)
hosts: rtr1
gather_facts: False
tasks:
- name: Diff against cisco ios configuration
cisco.ios.config:
intended_config: "{{ configs }}"
diff_against: intended
The Important Output:
Survey
Artifacts
The playbook "read_stats.yml" output
The '--- before' DIFF is the running configuration on the router. The --- after DIFF is the backup config "intended" saved as an artifact. Since we ran a second playbook to change the router's Loopback0 description, we can subsequently glean the change "DIFF" in red "- description tutorial".
Complete!
Other Links:
Ansible4Networking Meetup
Ansible4Networking Youtube
Ansible4Networking Upcoming Event
Looks interesting, thanks for sharing!