Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


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



Install Docker

Start by clicking on the docker icon ( windows ) 

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

docker pull juniper/pyez-ansible

docker images



Check Ansible roles

Juniper.junos role  role is hosted on the Ansible Galaxy website

install module

ansible-galaxy install Juniper.junos

ansible-galaxy list -p roles


Code Block
titlelist roles
collapsetrue
/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 #


Create Ansible files and playbooks

Create an directory ( on the windows host )  + 


mkdir facts_playbooks

 cd facts_playbook/


and create the hosts 

vi hosts 

Code Block
titlehosts
collapsetrue
[vMX]
192.168.99.11


and create playbook.yml 

Code Block
titlenew 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

Code Block
titleplaybook.yml
collapsetrue
---
- 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 and log back in : RUN & EXEC

Start the container:


cd   ~/Documents/ansiblescript/facts_playbook


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


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

juniper/pyez-ansible   is the docker image





Code Block
titleansible version
collapsetrue
/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



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

ansible-playbook -i hosts playbook.yml


Code Block
titleoutput of playbook
collapsetrue
/project # ansible-playbook -i hosts pbk_getfacts.yml
[DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to allow bad characters in group names by
default, this will change, but still be user configurable on deprecation. This feature will be removed in version
2.10. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [Get facts] ***************************************************************************************************

TASK [Get junos facts] *********************************************************************************************
[WARNING]: Platform linux on host 172.30.95.174 is using the discovered Python interpreter at /usr/bin/python, but
future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
ok: [172.30.95.174]

TASK [Print facts] *************************************************************************************************
ok: [172.30.95.174] => {
    "junos": {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python",
            "junos": {
                "HOME": "/var/home/********",
                "RE0": {
                    "last_reboot_reason": "0x200:normal shutdown",
                    "mastership_state": "master",
                    "model": "RE-SRX300",
                    "status": "OK",
                    "up_time": "103 days, 18 hours, 47 minutes, 47 seconds"
                },
                "RE1": null,
                "RE_hw_mi": false,
                "current_re": [
                    "master",
                    "node",
                    "fwdd",
                    "member",
                    "pfem",
                    "backup",
                    "fpc0",
                    "re0",
                    "fpc0.pic0"
                ],
                "domain": null,
                "fqdn": null,
                "has_2RE": false,
                "hostname": "SRX300-1-RL102",
                "hostname_info": {
                    "re0": "SRX300-1-RL102"
                },
                "ifd_style": "CLASSIC",
                "junos_info": {
                    "re0": {
                        "object": {
                            "build": 10,
                            "major": [
                                19,
                                4
                            ],
                            "minor": "1",
                            "type": "R"
                        },
                        "text": "19.4R1.10"
                    }
                },
                "master": "RE0",
                "master_state": true,
                "model": "SRX300",
                "model_info": {
                    "re0": "SRX300"
                },
                "personality": "SRX_BRANCH",
                "re_info": {
                    "default": {
                        "0": {
                            "last_reboot_reason": "0x200:normal shutdown",
                            "mastership_state": "master",
                            "model": "RE-SRX300",
                            "status": "OK"
                        },
                        "default": {
                            "last_reboot_reason": "0x200:normal shutdown",
                            "mastership_state": "master",
                            "model": "RE-SRX300",
                            "status": "OK"
                        }
                    }
                },
                "re_master": {
                    "default": "0"
                },
                "re_name": "re0",
                "serialnumber": "CV3016AF0526",
                "srx_cluster": false,
                "srx_cluster_id": null,
                "srx_cluster_redundancy_group": null,
                "switch_style": "VLAN_L2NG",
                "vc_capable": false,
                "vc_fabric": null,
                "vc_master": null,
                "vc_mode": null,
                "version": "19.4R1.10",
                "version_RE0": "19.4R1.10",
                "version_RE1": null,
                "version_info": {
                    "build": 10,
                    "major": [
                        19,
                        4
                    ],
                    "minor": "1",
                    "type": "R"
                },
                "virtual": false
            }
        },
        "changed": false,
        "facts": {
            "HOME": "/var/home/********",
            "RE0": {
                "last_reboot_reason": "0x200:normal shutdown",
                "mastership_state": "master",
                "model": "RE-SRX300",
                "status": "OK",
                "up_time": "103 days, 18 hours, 47 minutes, 47 seconds"
            },
            "RE1": null,
            "RE_hw_mi": false,
            "current_re": [
                "master",
                "node",
                "fwdd",
                "member",
                "pfem",
                "backup",
                "fpc0",
                "re0",
                "fpc0.pic0"
            ],
            "domain": null,
            "fqdn": null,
            "has_2RE": false,
            "hostname": "SRX300-1-RL102",
            "hostname_info": {
                "re0": "SRX300-1-RL102"
            },
            "ifd_style": "CLASSIC",
            "junos_info": {
                "re0": {
                    "object": {
                        "build": 10,
                        "major": [
                            19,
                            4
                        ],
                        "minor": "1",
                        "type": "R"
                    },
                    "text": "19.4R1.10"
                }
            },
            "master": "RE0",
            "master_state": true,
            "model": "SRX300",
            "model_info": {
                "re0": "SRX300"
            },
            "personality": "SRX_BRANCH",
            "re_info": {
                "default": {
                    "0": {
                        "last_reboot_reason": "0x200:normal shutdown",
                        "mastership_state": "master",
                        "model": "RE-SRX300",
                        "status": "OK"
                    },
                    "default": {
                        "last_reboot_reason": "0x200:normal shutdown",
                        "mastership_state": "master",
                        "model": "RE-SRX300",
                        "status": "OK"
                    }
                }
            },
            "re_master": {
                "default": "0"
            },
            "re_name": "re0",
            "serialnumber": "CV3016AF0526",
            "srx_cluster": false,
            "srx_cluster_id": null,
            "srx_cluster_redundancy_group": null,
            "switch_style": "VLAN_L2NG",
            "vc_capable": false,
            "vc_fabric": null,
            "vc_master": null,
            "vc_mode": null,
            "version": "19.4R1.10",
            "version_RE0": "19.4R1.10",
            "version_RE1": null,
            "version_info": {
                "build": 10,
                "major": [
                    19,
                    4
                ],
                "minor": "1",
                "type": "R"
            },
            "virtual": false
        },
        "failed": false,
        "warnings": [
            "Platform linux on host 172.30.95.174 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information."
        ]
    }
}

PLAY RECAP *********************************************************************************************************
172.30.95.174              : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  

/project # 




Check connectivity

Basic check netconfig

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


Code Block
titlecheck netconfig
collapsetrue
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




Basic snapy








...