Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 19 Next »


https://hub.docker.com/r/juniper/pyez-ansible/




Configuration on the Device

vMX config for ansible + Netconfig

set system login user ansible class super-user
set system login user ansible authentication encrypted-password "$1$rgdhLoHQ$/eV08mYSvYSBsaHbyaPTp/"            ## ansible123
set system services ssh root-login allow
set system services ssh protocol-version v2
set system services netconf ssh

Local netconfig Test:


Remote netconfig test

ssh ansible@192.168.56.11 -p 830 -s netconf





Start by clicking on the docker icon ( windows ) 

search for available containerdocker search juniper
pull the image ( optional)

docker pull juniper/pyez-ansible

docker images



Create an directory ( on the windows host )  + 


mkdir facts_playbooks

 cd facts_playbook/


and create the hosts 

vi hosts 

hosts
[vMX]
192.168.99.11

and create playbook.yml 

vi pbk_getfacts.yml

new module
/project # more pbk_getfacts.yml
---
- name: Get facts
  hosts: All-srx
  connection: local
  gather_facts: no
  roles:
    - Juniper.junos

  tasks:
    - name: Get junos facts
      juniper_junos_facts:
        host: "{{ inventory_hostname }}"
        user: "Netbox"
        passwd: "Netbox"
      register: junos
    - name: Print facts
      debug:
        var: junos

vi playbook.yml    with OLD module

playbook.yml
---
- name: Get facts
  hosts: vMX
  connection: local
  gather_facts: no
  
  roles:
  - Juniper.junos
  
  #vars_prompt:
  #- name: ADMUSER
  #    prompt: Username
  #    private: no
  #- name: ADMPASS
  #   prompt: password
  #   private: yes

  tasks:
  - name: Get junos facts
    junos_get_facts:
      #host: "{{ inventory_hostname }}"
      host: vMX
      #user: "{{ ADMUSER }}"
      user: "ansible"
      #passwd: "{{ ADMPASS }}"
      passwd: "ansible123"
    register: junos
  - name: Print facts
    debug:
      var: junos


Start the container:


cd   ~/Documents/ansiblescript/facts_playbook


docker run -it --rm -v $PWD:/project juniper/pyez-ansible ash


-it
--rm
-v    $PWD         is the host directory
        :/project    is the container directory

juniper/pyez-ansible   is the docker image


ansible version
/project # ansible --version
ansible 2.9.5
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Apr 22 2019, 10:28:12) [GCC 6.3.0]

/project # python --version
Python 3.6.8


Juniper.junos role is hosted on the Ansible Galaxy website

install module

ansible-galaxy install Juniper.junos

ansible-galaxy list -p roles


list roles
/project # ansible-galaxy  list -p roles
# /root/.ansible/roles
- Juniper.junos, 2.3.2
# /etc/ansible/roles
- Juniper.junos, (unknown version)
[WARNING]: - the configured path /project/roles does not exist.
[WARNING]: - the configured path /usr/share/ansible/roles does not exist.
/project #

Basic test with hosts & playbook.yml file:

cd project

ansible-playbook -i hosts playbook.yml





Basic check netconfig

ansible-playbook -i hosts chk_netconf.yml -k -u Netbox


check netconfig
more chk_netconf.yml
---
- name: Get Device Facts
  hosts: All-srx
  roles:
    - Juniper.junos
  connection: local
  gather_facts: no

  tasks:
    - name: Checking NETCONF connectivity
      wait_for:
        host: "{{ inventory_hostname }}"
        port: 830
        timeout: 5

    - name: Retrieving information from devices running Junos OS
      juniper_junos_facts:
        host: "{{ inventory_hostname }}"

    - name: Print version
      debug:
        var: junos.version
















  • No labels