Wednesday, October 21, 2020

Ansible outputting multiple variables to a file.

Im gathering information on cisco switches (specifically the interfaces without acls and the hostnames of the switches) and im able to do that just fine but where I run into issues is with outputting that all into a csv file. I want it to add every interface it finds, not just the last one. And I want to be able to have multiple variables appear in the csv files.

How would I go about doing that? Here is my current code.

InterfacesWithoutACLs.yml:

---

- name: 'internet failover'

connection: network_cli

hosts: allPrimarySwitch

pre_tasks:

- name: 'gather ios facts'

ios_facts:

gather_subset: min

gather_network_resources:

- l3_interfaces

tasks:

- name: 'get interfaces'

ios_command:

commands: 'show ip interface brief | exclude unassigned|Interface'

register: get_interfaces

- name: 'set interface variables'

set_fact:

interfaces: ""

- name: 'import configuration role'

with_items: ""

include_role:

name: configure_dhcp_helper

vars:

interface: ""

- name: Generate report

local_action: copy content= dest=/etc/ansible/dev/Bradley/InterfacesWithoutACL.csv

changed_when: False

run_once: true

main.yml:

---

- name: 'get interface config'

ios_command:

commands: "show running-config interface | sec interface"

register: get_interface_config

- debug:

var: get_interface_config.stdout_lines[0][0]

when: get_interface_config.stdout is search('ip access-group') != 1

- name: 'get hostname'

ios_command:

commands: "show running-config | sec hostname"

register: get_hostname



No comments:

Post a Comment