User Tools

Site Tools


network_stuff:juniper:ansible_for_junos

AN EXAMPLE OF INSTALLATION:
In the hub:

alias python="/usr/bin/python3.6" # Add this in bashrc
cat > requirements.txt
ansible==2.8.7
paramiko
netaddr
yamllint
ansible-galaxy collection install juniper.device
pip3 unistall oci
pip3 unistall oci-cli
pip3 install -r requirements.txt
pip3 install -U junos-eznc
pip3 install junos-eznc
pip3 install jxmlease
yum install ansible # 2.9.16
ansible-galaxy install Juniper.junos 
~ In /etc/ansible/ansible.cfg # change the python version in the ansible interpreter:
[defaults]
  host_key_checking = False
  host_key_check = False
  interpreter_python = /usr/bin/python3.6
ansible-config dump --only-changed # Is still not picking the new python so we need to put it as inventory for the host or group_vars/host_vars and it will be picked up

We can automate a little more the ansible installation with a requirements.txt file:

cat requirements.txt # this is an example of file:
# change colors section in **/etc/ansible/ansible.cfg**
[colors]
verbose = cyan
error = white

In the target boxes:

set system services netconf ssh port 22

But anyway we need to open port 830 in the switches' control plane (if any RE-protect acl). This below is to test netconf access with a python script

#!/usr/bin/env python3
from jnpr.junos import Device

def main():
    host = "X.X.X.X"
    user = "foo"
    password = "bar"
    pyez_test = PYEZ_TEST(host, user, password)
    pyez_test.do_work()

class PYEZ_TEST:
    """ class docstring
    """
    def __init__(self, host, user, password):
        """ Initialise the PYEZ_TEST class
        """
        self.host = host
        self.user = user
        self.password = password
    def do_work(self):
        """ connects to host using context manager syntax
            pulls down the configuration and device facts
        """
        with Device(host=self.host, user=self.user, passwd=self.password) as self.dev:
            print(self.dev.rpc.get_config(options={"format": "json"}))
            print(self.dev.facts)

if __name__ == "__main__":
   main()

network_stuff/juniper/ansible_for_junos.txt · Last modified: by 127.0.0.1