1s & 0s-Current Trends in DC Networking - Arista Ansible Config

Started by that1guy15, March 01, 2017, 12:04:01 PM

Previous topic - Next topic

that1guy15

Current Trends in DC Networking - Arista Ansible Config

Over the past few post I have covered the basics of Ansible, now its time to dig in and see how we can leverage it to build configurations. The cool thing about Ansible is there is a number of ways to accomplish most task. From here on out, it's honestly about exploring what options are available within Ansible and expanding skills as you learn.

This post we will focus on configuring the Arista
Source: Current Trends in DC Networking - Arista Ansible Config

From http://blog.movingonesandzeros.net/
That1guy15
@that1guy_15
blog.movingonesandzeros.net

dlots

Very nice!!

How hard would it be to have Ansible take a CSV something like

1 2 3 4,192.168.0.1/24,10.0.0.1/24,10.10.10.10/32, (ETC)
2 3 4 5, 10.0.0.62/24,10.1.2.3/24, 10.5.4.3/32, (ETC)
(ETC)

and spit out a config for each line?  I am sure I could write something in Python to build the yml files, but I was hoping there was something I could do automatically.

Can't wait till I get an Ansable machine at here :-)

that1guy15

Look at the for loops in the template files along with how the variable vlan is used in all.yml of this blog post.
Take the CSV and convert it to a nested list and import it into the Ansible playbook.

Then in a task just like mine build out the config using a template and dump it to a file.
The template file would give the config structure and where to place the elements of the nested lists just like I do with vlans.

that would be my first thought.

So your template is literally a mix between raw text and variables like so:

----------------------------------------------
Some raw text and now a {{ var.IP }}
some more raw text and another {{ var.subnet }}
Networking-forums.com rules!!!
----------------------------------------------

your variable would be something like:

var:
  - { IP: 1.1.1.1, subnet: "/24", name: PROD }
  - { IP: 2.2.2.2, subnet: "/24", name: QA }


This would output:
----------------------------------------------
Some raw text and now a 1.1.1.1
some more raw text and another /24
Networking-forums.com rules!!!
----------------------------------------------
That1guy15
@that1guy_15
blog.movingonesandzeros.net

that1guy15

Serious my recommendation if work is going to drag their ass on getting you something then setup your home system with a VM or Vagrant and build out a lab. Or spin up a free web-hosting instance on AWS or Digital Ocean and start going to town.

Ansible is one of those you just gotta start mucking with.
That1guy15
@that1guy_15
blog.movingonesandzeros.net

dlots

Yeah, that seems like a good plan.
I'll see what I can come up with over the weekend.  :-)

Thank you

NetworkGroover

Pretty much as long as you have the the programming know-how the possibilities are almost endless.
Engineer by day, DJ by night, family first always

wintermute000

python dynamic inventory exists in ansible for this purpose - write some code to manipulate your data into JSON basically
then point ansible to your .py instead of the normal yaml files

my own hacky example here :)

https://github.com/wintermute000/ansible-cisco-conf


basically you want to throw something like this at ansible


#  EXAMPLE JSON OUTPUT IN ANSIBLE INVENTORY FORMAT


# {"group": {
#     "hosts": ["ACCESS-SW1", "ACCESS-SW2", "ACCESS-SW3"]
# }, "_meta": {
#     "hostvars": {
#         "ACCESS-SW1": {
#             "description": {
#                 "g1/0/12-22": "User VLAN 30 + Voice",
#                 "g1/0/1-11": "User VLAN 10 + Voice",
#                 "g1/0/24": "Port-channel 1 member",
#                 "g1/0/23": "Port-channel 1 member",
#                 "Po1": "Uplink to core"
#             },
#             "parameters": {
#                 "g1/0/12-22": "spanning-tree portfast",
#                 "g1/0/1-11": "spanning-tree portfast",
#                 "g1/0/24": "speed auto\nduplex auto",
#                 "g1/0/23": "speed auto\nduplex auto",
#                 "Po1": "switchport trunk native vlan 999"
#             },
#             "trunk": {
#                 "Po1": "10,20,30,40"
#             },
#             "etherchannel": {
#                 "g1/0/24": "1",
#                 "g1/0/23": "1"
#             },
#             "access_data": {
#                 "g1/0/12-22": "30",
#                 "g1/0/1-11": "10"
#             },
#             "access_voice": {
#                 "g1/0/12-22": "40",
#                 "g1/0/1-11": "40"
#             }
#         },
#         "ACCESS-SW3": {
#             "description": {
#                 "g1/0/24": "Port-channel 3 member",
#                 "Po3": "Uplink to core",
#                 "g1/0/23": "Port-channel 3 member",
#                 "g1/0/1-22": "User VLAN 10 + Voice"
#             },
#             "parameters": {
#                 "g1/0/12-22": "spanning-tree portfast",
#                 "g1/0/1-11": "spanning-tree portfast",
#                 "Po3": "switchport trunk native vlan 999"
#             },
#             "trunk": {
#                 "Po3": "10,20,30,40"
#             },
#             "etherchannel": {
#                 "g1/0/24": "3",
#                 "g1/0/23": "3"
#             },
#             "access_data": {
#                 "g1/0/1-22": "10"
#             },
#             "access_voice": {
#                 "g1/0/1-22": "40"
#             }
#         },
#         "ACCESS-SW2": {
#             "description": {
#                 "g1/0/12-22": "User VLAN 30 + Voice",
#                 "g1/0/1-11": "User VLAN 10 + Voice",
#                 "g1/0/24": "Port-channel 2 member",
#                 "Po2": "Uplink to core",
#                 "g1/0/23": "Port-channel 2 member"
#             },
#             "parameters": {
#                 "g1/0/12-22": "spanning-tree portfast",
#                 "g1/0/1-11": "spanning-tree portfast",
#                 "Po2": "switchport trunk native vlan 999"
#             },
#             "trunk": {
#                 "Po2": "10,20,30,40"
#             },
#             "etherchannel": {
#                 "g1/0/24": "2",
#                 "g1/0/23": "2"
#             },
#             "access_data": {
#                 "g1/0/12-22": "30",
#                 "g1/0/1-11": "20"
#             },
#             "access_voice": {
#                 "g1/0/12-22": "40",
#                 "g1/0/1-11": "40"
#             }
#         }
#     }
# }}