Main page: 1- Ansible
https://hub.docker.com/r/juniper/pyez-ansible/
Commands:
docker pull juniper/pyez-ansible
docker run -it --rm juniper/pyez-ansible ash
Configuration on the Device | vMX config for ansible + Netconfig
|
...
Local netconfig Test: | |
Remote netconfig test | ssh ansible@192.168.56.11 -p 830 -s netconf |
Install Docker | ||||||||
---|---|---|---|---|---|---|---|---|
Start by clicking on the docker icon ( windows ) | ||||||||
search for available container | docker search juniper | |||||||
pull the image ( optional) |
| |||||||
Check Ansible roles | ||||||||
|
ansible-galaxy list -p roles
| |||||||
Create Ansible files and playbooks | ||||||||
Create an directory ( on the windows host ) + | mkdir facts_playbookscd facts_playbook/ | |||||||
and create the hosts | vi hosts
| |||||||
and create playbook.yml | vi pbk_getfacts.yml |
...
jkriker@jkriker-T460 MINGW64 ~/Documents/ansiblescript
$ cd facts_playbook/
jkriker@jkriker-T460 MINGW64 ~/Documents/ansiblescript/facts_playbook
$ ls
hosts playbook.yml
Start the container:
vi playbook.yml with OLD module
| ||||||||||||
Start and log back in : RUN & EXEC | ||||||||||||
Start the container: |
-it |
...
/ --volume $PWD is the host directory
| ||||||||||||
log back in the container ( exec <container> ) | docker ps docker exec -it funny_kirch ash /playbooks # cd /project/ | |||||||||||
basic playbook | ||||||||||||
Basic test with hosts & playbook.yml file: | cd project
| hosts and
| .yml
| |||||||||
import sys
import json
import yaml
from pprint import pprint
from jnpr.junos import Device
from jnpr.junos.exception import ConnectError
dev = Device(host='192.168.99.11',user='ansible',passwd='ansible123')
try:
dev.open()
except ConnectError as err:
print ("Cannot connect to device: {0}".format(err))
sys.exit(1)
#print("#print everything\n")
#pprint (dev.facts)
#print("\n#print only the version")
#pprint (dev.facts['version'])
print (yaml.dump(dev.facts))
#print (json.dumps(dev.facts))
dev.close() | ||||||||||||
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||||
Check connectivity | ||||||||||||
Basic check netconfig | ansible-playbook -i hosts chk_netconf.yml -k -u Netbox
| |||||||||||
Basic jsnapy | ||||||||||||
check jsnapy | pip3 install -U jsnapy jsnapy --version | |||||||||||
default jsnapy folder | ls /etc/jsnapy/ -al more /etc/jsnapy/jsnapy.cfg more /etc/jsnapy/logging.yml
| |||||||||||
config file | ||||||||||||
test file | ||||||||||||
Basic jsnapy command | ||||||||||||
config file | /project # more /project/jsnapy-demo/configfiles/config1.yml
| |||||||||||
test file | /project # vi /project/jsnapy-demo/testfiles/show_bgp_summary.yml
| |||||||||||
run jsnapy | jsnapy --snapcheck pre -f jsnapy-demo/configfiles/config1.yml | |||||||||||
snapshot output file | sudo apt-get install libxml2-utils xmllint --format ~/jsnapy/snapshots/172.30.95.177_pre_show_bgp_neighbor.xml
| |||||||||||
snapshot database |