Skip to content

Instantly share code, notes, and snippets.

View cidrblock's full-sized avatar

Bradley A. Thornton cidrblock

View GitHub Profile
@cidrblock
cidrblock / run.py
Last active July 10, 2019 20:28
Ansible runner demo
""" ansible runner demo
"""
from functools import reduce
import operator
import yaml
import ansible_runner
def dict_get(data_dict, keypath):
map_list = keypath.split('.')
@cidrblock
cidrblock / output.yaml
Created August 10, 2019 15:16
playbook output using name.jetpack.gather_states
PLAY [all] *************************************************************************************************************************************************************************
TASK [gather_states : Build a list of state gatherers] *****************************************************************************************************************************
ok: [eos101]
ok: [vyos101]
ok: [eos102]
ok: [ios102]
ok: [nxos101]
@cidrblock
cidrblock / gencsv.py
Created December 5, 2019 17:53
Make a disposition CSV for ansible content
import os
from ansible.parsing.plugin_docs import read_docstring
from pprint import pprint
import csv
import yaml
path = "./ansible/"
@cidrblock
cidrblock / build.sh
Last active February 19, 2020 14:11
Build an ansible environment with network collections from source
#!/bin/bash
############
# run this file as `source build.sh`
############
# venv
python3 -m venv venv
source venv/bin/activate
pip install wheel
pip install paramiko
from datetime import datetime, timezone
import dateutil.parser
from github3 import GitHub
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
github = GitHub(token=GITHUB_TOKEN)
org = github.organization('ansible-collection-migration')
# (venv) ➜ argspec_test python go.py
# Estimated file length is 3121
# Loading python file took 0.1354 seconds
# Loading yaml(python parser) file took 4.1489 seconds
# Loading yaml(C parser) file took 0.4825 seconds
# (venv) ➜ argspec_test
import contextlib
import astor
import ast
import ruamel.yaml
import os
import re
import sys
COLPATH = "./"
COLLECTION = "arista.eos"
SUBDIRS = ("modules", "action")
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network_template import (
NetworkTemplate,
)
class MyTemplate(NetworkTemplate):
def __init__(self, lines=None):
super(MyTemplate, self).__init__(lines=lines, tmplt=self)
PARSERS = [
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network_template import (
NetworkTemplate,
)
class MyTemplate(NetworkTemplate):
def __init__(self, lines=None):
super(MyTemplate, self).__init__(lines=lines, tmplt=self)
PARSERS = [
(venv) ➜ parser_plugin ansible-playbook iptables.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [localhost] ********************************************************************************************************************************************
TASK [command] **********************************************************************************************************************************************
changed: [localhost]
TASK [debug] ************************************************************************************************************************************************