Ansible plugins and modules to make network automation easier.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
filter_plugins
.gitignore
LICENSE
README.md
example_confparse.yml
example_confparse_crypto.yml
requirements-dev.txt
requirements.txt
setup.cfg
simple_example.yml
tests_to_add.txt

README.md

ansible_helpers

Ansible plugins and modules to make network automation easier.


Using net_txtfsm_parse filter

Purpose

Convert unstructured data from Ansible core networking modules (like ios_command, eos_command, nxos_command) into structured data using TextFSM templates.

Example Use

# Send output through the filter (specify two arguments platform and command)
- debug:
    msg: "{{ output | net_textfsm_parse('cisco_ios', 'show ip int brief') }}"

Setup

# Clone this repository
git clone https://github.com/ktbyers/ansible_helpers

# Get ntc-templates
git clone https://github.com/networktocode/ntc-templates

# PIP install any of the dependencies specified in requirements.txt
pip install -r /path/to/ansible_helpers/requirements.txt

# Setup environment variable
export NET_TEXTFSM=/path/to/ntc-templates/templates/

# Copy /path/to/ansible_helpers/filter_plugins to either:
1. ./filter_plugins directory relative to your playbook
2. a central filter_plugins directory as specified in your .ansible.cfg

More Detailed Example

See https://github.com/ktbyers/ansible_helpers/blob/master/simple_example.yml



Using confparse_parent filter

Purpose

Allow use of CiscoConfParse to parse space-based hierarchical configurations and to make logical decisions from the results.

Example Use

- name: Use confparse_parent filter to find 3DES crypto maps
  set_fact:
    crypto_list: "{{ show_run | confparse_parent(parent='^crypto map CRYPTO', child='3DES-SHA') }}"

The returned data structure looks as follows:

    "crypto_list": [
        [
            false, 
            "crypto map CRYPTO 10 ipsec-isakmp ", 
            null
        ], 
        [
            true, 
            "crypto map CRYPTO 20 ipsec-isakmp ", 
            " set transform-set 3DES-SHA "
        ], 
        [
            true, 
            "crypto map CRYPTO 30 ipsec-isakmp ", 
            " set transform-set 3DES-SHA "
        ], 
        [
            false, 
            "crypto map CRYPTO 40 ipsec-isakmp ", 
            null
        ], 
        [
            false, 
            "crypto map CRYPTO 50 ipsec-isakmp ", 
            null
        ]
    ]

Where:

  • element[0] is a boolean indicating whether the child condition was matched
  • element[1] is the matching parent configuration line
  • element[2] is the matching child configuration line (or null if not found).

Setup

# Clone this repository
git clone https://github.com/ktbyers/ansible_helpers

# PIP install any of the dependencies specified in requirements.txt
pip install -r /path/to/ansible_helpers/requirements.txt

# Copy /path/to/ansible_helpers/filter_plugins to either:
1. ./filter_plugins directory relative to your playbook
2. a central filter_plugins directory as specified in your .ansible.cfg

More Detailed Example

See https://github.com/ktbyers/ansible_helpers/blob/master/example_confparse.yml