This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sample Makefile for ansible | |
clean: | |
rm -f ./diffs/*; rm -rf ./compiled/*; rm -rf ./logs/* # this cleans up all the temporary files a normal ansible run produces. It makes sure every ansible run starts from scratch and does not have any stale file | |
prod_compare: clean # this invokes clean first, then runs ansible in "check mode", creates a diff in diffs/ (configured in main_playbook.yml) and runs 25 devices at a time to speed it up. $(opt) is used to allow you to add ansible options to the invokation from the commandline by doing "make prod_compare opt="--limit nycrouter1"" for example. | |
ansible-playbook -i hosts main_playbook.yml -e user=$(USER) --check -f25 $(opt); \ | |
touch last_compare_time # this is here as a timestamp of the last time you ran compare. used in deploy to catch cowboys. | |
prod_deploy: clean # this is the real deal and actually deploys config. everything before the ansible call is done so that this will refuse to launch if you have any var file with a timestamp newer than "last_compare_t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Virtual Envs in 5 minutes or less. | |
A deeper dive on this can be found here: https://realpython.com/python-virtual-environments-a-primer/ (i only skimmed this though) | |
Ansible is python-based and has many dependency libraries and sometimes its behavior can change drastically based on which version of the required libraries you use. | |
For that reason, i think it's a good idea to have a python "venv". A self contained set of libraries and other requirements that will guarantee your ansible setup will behave pretty much the same on yours or someone else's computer. | |
By following the below steps you should have | |
1. a project directory where all the files for your ansible setup live |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ansible for Network management basic layout | |
# This is just my personal take on this based on my experience but there are many ways to skin the cat | |
my_ansible_Setup\ # Project folder containing everything | |
groups_vars/ # groups are defined in [brackets] in the inventory file. Each group can have a respective var file in group_vars that will contain variables that apply to the whole group. | |
geo_nyc.yaml # sample of a group file that applies common settings for all network devices in the NYC geographical area. Things such as radius, ntp, dns servers for example. | |
host_vars/ # each device defined in inventory can have a dedicated file in this folder containing variables specific only to this device. things like interface IPs, hostnames etc. go here | |
nycrouter1.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
test_applications: | |
- rpc: get-bgp-neighbor-information | |
- item: | |
id: ./peer-id | |
xpath: '//bgp-information/bgp-peer[peer-id="X.YYY.YYY.X"]' | |
tests: | |
- exists: //peer-id | |
info: "Test Succeeded!!, peer-id is {{post['peer-id']}}" | |
err: "Test Failed!!!, peer-id is {{post['peer-id']}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am itsgc on github. | |
* I am itsgc (https://keybase.io/itsgc) on keybase. | |
* I have a public key whose fingerprint is CD95 E84B 435E 9741 2CE8 1A7F BD9B BBA9 82B1 1608 | |
To claim this, I am signing this object: |