Coder Social home page Coder Social logo

ksator / microservice_collect_junos_configuration Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 5.0 23 KB

Microservice to collect Junos configuration. Based on Ansible and Docker

License: MIT License

Dockerfile 60.04% Shell 39.96%
network-automation junos-automation ansible docker junos

microservice_collect_junos_configuration's Introduction

Docker Cloud Automated build Docker Cloud Build Status Docker Pulls MicroBadger Layers MicroBadger Size

Description

This microservice collects Junos configuration
It uses Docker and Ansible.
This microservice:

  • instanciates a container
  • executes the service (collects Junos configuration)
  • stops the container
  • removes the container

The Docker image is ksator/collect-junos-configuration

Usage

Install Docker

Pull the Docker image

$ docker pull ksator/collect-junos-configuration


Verify

$ docker images ksator/collect-junos-configuration
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
ksator/collect-junos-configuration   latest              972f17f4a0c0        14 minutes ago      543MB

Create the microservice inputs

Create this structure:

  • An inputs directory. With these files:
    • An Ansible Inventory file (hosts.ini) with following variables:
      • ansible_host: IP of the device
      • ansible_ssh_user: Username to use for the connection
      • ansible_ssh_pass: Password to use for the connection
    • A YAML file (format_to_use_when_collecting_configuration.yml) to indicate the desired format for the Junos configuration.
      • The default format is text.
      • Supported formats are:
        • text
        • json
        • xml
        • set
$ ls inputs/
format_to_use_when_collecting_configuration.yml  hosts.ini

Ansible inventory example:

$ more inputs/hosts.ini
[spines]
demo-qfx10k2-14   ansible_host=172.25.90.67
demo-qfx10k2-15   ansible_host=172.25.90.68

[leaves]
demo-qfx5110-9    ansible_host=172.25.90.63
demo-qfx5110-10   ansible_host=172.25.90.64

[all:vars]
netconf_port=830
ansible_ssh_user=ansible
ansible_ssh_pass=juniper123

Configure the desired format for the Junos configuration (text, json, xml, set)
Example:

$ more inputs/format_to_use_when_collecting_configuration.yml

---
configuration:
  format: text

Run the microservice

This will instanciate a container, execute the service, stop the container and remove the container.

$ docker run -it --rm -v ${PWD}/inputs:/inputs -v ${PWD}/outputs:/outputs ksator/collect-junos-configuration

Collect Junos configuration

PLAY [collect junos configuration from devices] ***********************************************************************************************************************************************************************************************************************************

TASK [include_vars] ***************************************************************************************************************************************************************************************************************************************************************
ok: [demo-qfx5110-9]
ok: [demo-qfx5110-10]
ok: [demo-qfx10k2-14]
ok: [demo-qfx10k2-15]

TASK [include_vars] ***************************************************************************************************************************************************************************************************************************************************************
ok: [demo-qfx5110-9]
ok: [demo-qfx5110-10]
ok: [demo-qfx10k2-15]
ok: [demo-qfx10k2-14]

TASK [collect-configuration : Create output directory for each device] ************************************************************************************************************************************************************************************************************
changed: [demo-qfx5110-9]
changed: [demo-qfx10k2-15]
changed: [demo-qfx5110-10]
changed: [demo-qfx10k2-14]

TASK [collect-configuration : Collect configuration in text format from devices] **************************************************************************************************************************************************************************************************
ok: [demo-qfx5110-9]
ok: [demo-qfx5110-10]
ok: [demo-qfx10k2-15]
ok: [demo-qfx10k2-14]

TASK [collect-configuration : Copy collected configuration in a local directory] **************************************************************************************************************************************************************************************************
changed: [demo-qfx10k2-15]
changed: [demo-qfx5110-9]
changed: [demo-qfx10k2-14]
changed: [demo-qfx5110-10]

TASK [collect-configuration : Collect configuration in set format from devices] ***************************************************************************************************************************************************************************************************
skipping: [demo-qfx5110-9]
skipping: [demo-qfx5110-10]
skipping: [demo-qfx10k2-14]
skipping: [demo-qfx10k2-15]

TASK [collect-configuration : copy collected configuration in a local directory] **************************************************************************************************************************************************************************************************
skipping: [demo-qfx5110-9]
skipping: [demo-qfx5110-10]
skipping: [demo-qfx10k2-14]
skipping: [demo-qfx10k2-15]

TASK [collect-configuration : Collect configuration in json format from devices] **************************************************************************************************************************************************************************************************
skipping: [demo-qfx5110-9]
skipping: [demo-qfx5110-10]
skipping: [demo-qfx10k2-14]
skipping: [demo-qfx10k2-15]

TASK [collect-configuration : copy collected configuration in a local directory] **************************************************************************************************************************************************************************************************
skipping: [demo-qfx5110-9]
skipping: [demo-qfx5110-10]
skipping: [demo-qfx10k2-14]
skipping: [demo-qfx10k2-15]

TASK [collect-configuration : Collect configuration in xml format from devices] ***************************************************************************************************************************************************************************************************
skipping: [demo-qfx5110-9]
skipping: [demo-qfx5110-10]
skipping: [demo-qfx10k2-14]
skipping: [demo-qfx10k2-15]

TASK [collect-configuration : copy collected configuration in a local directory] **************************************************************************************************************************************************************************************************
skipping: [demo-qfx5110-9]
skipping: [demo-qfx5110-10]
skipping: [demo-qfx10k2-14]
skipping: [demo-qfx10k2-15]

PLAY RECAP ************************************************************************************************************************************************************************************************************************************************************************
demo-qfx10k2-14            : ok=5    changed=2    unreachable=0    failed=0   
demo-qfx10k2-15            : ok=5    changed=2    unreachable=0    failed=0   
demo-qfx5110-10            : ok=5    changed=2    unreachable=0    failed=0   
demo-qfx5110-9             : ok=5    changed=2    unreachable=0    failed=0   

List the containers.
The container doesnt exist anymore

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Check the microservice output

Here's the output generated

$ tree outputs/
outputs/
├── demo-qfx10k2-14
│   └── configuration.conf
├── demo-qfx10k2-15
│   └── configuration.conf
├── demo-qfx5110-10
│   └── configuration.conf
└── demo-qfx5110-9
    └── configuration.conf

4 directories, 4 files

microservice_collect_junos_configuration's People

Contributors

ksator avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.