Ansible Inventory Plugin, created to get hosts from HTTP API.

Overview

Build Dockerfile Build Ansible Collection

augustoliks/ws-inventory Docker Pulls

augustoliks/ws-inventory

ansible-ws-inventory-plugin

Ansible Inventory Plugin, created to get hosts from HTTP API.

Features:

  • Database compatible with MongoDB and Filesystem (JSON format);
  • Import inventory with .CSV file format;
  • Export inventory with .CSV file format.

Diagram

Configure Ansible Inventory Plugin: augustoliks.ws

Requirements

pip3 install requests

Installing the Collection from Ansible Galaxy

Before using the augustoliks.ws collection, you need to install it with the Ansible Galaxy CLI:

ansible-galaxy collection install augustoliks.ws

You can also include it in a requirements.yml file and install it via ansible-galaxy collection install -r requirements.yml, using the format:

---
collections:
  - name: augustoliks.ws
    version: 1.0.3

Usage

Create inventory file ws-iventory.yml, and configure follow options:

# Plugin Name
plugin: augustoliks.ws.inventory

# Plugin Options
api_endpoint: 'http://127.0.0.1:8000/hosts'
timeout: 10

Run Ansible playbook with ws-iventory.yml inventory.

ansible-playbook -i ws-iventory.yml main.yml 

Configure HTTP Server API

Webserver Source code is in the http-server-api/ directory.

Application wrapped in Container Image format, but it can be runs a system wide, with systemd or sysvinit etc.

Pull Docker Image

docker pull augustoliks/ws-inventory:latest

Configuration

Source code was made in Python. The configuration app, using a library dynaconf, for provides multiple formats to configure properties of project. For default, configuration was made in JSON file format, but it could be made from any other source and format compatible with a configuration library.

{
  "filesystem": {
    "BIND_ADDRESS": "0.0.0.0",
    "BIND_PORT": 5000,
    "URI_ROOT_PATH": "/",
    "LOG_LEVEL": "DEBUG",
    "DB_DRIVER": "filesystem",
    "DB_OPTS": {
      "file": "/tmp/inventory.json"
    }
  },
  "mongodb": {
    "BIND_ADDRESS": "0.0.0.0",
    "BIND_PORT": 5000,
    "URI_ROOT_PATH": "/",
    "LOG_LEVEL": "DEBUG",
    "DB_DRIVER": "mongodb",
    "DB_OPTS": {
      "url": "mongodb://root:root@mongodb:27017"
    }
  }
}
  • ENV_FOR_DYNACONF: Select high level set properties. Options available: mongodb, filesystem;

  • BIND_ADDRESS: Bind of HTTP Server address uvicorn;

  • BIND_PORT: Port of HTTP Server uvicorn;

  • LOG_LEVEL: Log of application. Levels available: DEBUG, INFO, WARNING, ERROR, CRITICAL;

  • URI_ROOT_PATH: Base URI path routes of webserver (util in reverse proxys servers nginx, apache, traefix);

  • DB_DRIVER: Persistence Tecnology. This option choosed, change properties of DB_OPTS properties. Technologies available: mongodb, filesystem

  • DB_OPTS: Properties access Persist Layer:

    • mongodb:

      • url: URL with basic-auth to access mongodb instance
    • filesystem:

      • file: Path of file which will be used with database.

Example Complete

cd examples/
  • Install dependencies (require virtualenv):
virtualenv venv
source venv/bin/activate
pip3 install -r requirements.txt
ansible-galaxy collection install -r requirements.yml
  • Provides ws-inventory and mongodb container instances:
docker-compose pull
docker-compose up -d
  • Insert hosts:

drawing

  • List hosts:

drawing

  • Check playbook-main.yml properties:

⚠️ augustoliks should be change with your system username.

$ cat playbook-main.yml                                                                                                     

---
- hosts: all
  remote_user: augustoliks
  become_user: augustoliks
  become: yes
  gather_facts: False

  tasks:
    - ansible.builtin.debug:
        var: hostvars
  • Check ws-inventory.yml properties:
$ cat ws-inventory.yml                                                                                                      

plugin: "augustoliks.ws.inventory"
api_endpoint: "http://127.0.0.1:5000/read/hosts"
timeout: 10
  • Test plugin
$ ansible-inventory -i ws-inventory.yml --graph
$ ansible-inventory -i ws-inventory.yml --list
  • Run playbook
$ ansible-playbook -i ws-inventory.yml playbook-main.yml --ask-pass                                                         

SSH password: 

PLAY [all] ********************************************************************************************************************

TASK [ansible.builtin.debug] **************************************************************************************************
ok: [localhost] => {
    "hostvars": {
        "localhost": {
            ...
            "location": {
                "address": "string",
                "latitude": 35.1234,
                "longitude": 10.1234
            },
            ...
        }
    }
}

PLAY RECAP ********************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0                                                                     
You might also like...
High-performance Async REST API, in Python. FastAPI + GINO + Arq + Uvicorn (w/ Redis and PostgreSQL).

fastapi-gino-arq-uvicorn High-performance Async REST API, in Python. FastAPI + GINO + Arq + Uvicorn (powered by Redis & PostgreSQL). Contents Get Star

 Turns your Python functions into microservices with web API, interactive GUI, and more.
Turns your Python functions into microservices with web API, interactive GUI, and more.

Instantly turn your Python functions into production-ready microservices. Deploy and access your services via HTTP API or interactive UI. Seamlessly export your services into portable, shareable, and executable files or Docker images.

Restful Api developed with Flask using Prometheus and Grafana for monitoring and containerization with Docker :rocket:
Restful Api developed with Flask using Prometheus and Grafana for monitoring and containerization with Docker :rocket:

Hephaestus 🚀 In Greek mythology, Hephaestus was either the son of Zeus and Hera or he was Hera's parthenogenous child. ... As a smithing god, Hephaes

Boilerplate code for quick docker implementation of REST API with JWT Authentication using FastAPI, PostgreSQL and PgAdmin ⭐

FRDP Boilerplate code for quick docker implementation of REST API with JWT Authentication using FastAPI, PostgreSQL and PgAdmin ⛏ . Getting Started Fe

A comprehensive CRUD API generator for SQLALchemy.
A comprehensive CRUD API generator for SQLALchemy.

FastAPI Quick CRUD Introduction Advantage Constraint Getting started Installation Usage Design Path Parameter Query Parameter Request Body Upsert Intr

Fast, simple API for Apple firmwares.

Loyal Fast, Simple API for fetching Apple Firmwares. The API server is closed due to some reasons. Wait for v2 releases. Features Fetching Signed IPSW

API for Submarino store

submarino-api API for the submarino e-commerce documentation read the documentation in: https://submarino-api.herokuapp.com/docs or in https://submari

LuSyringe is a documentation injection tool for your classes when using Fast API

LuSyringe LuSyringe is a documentation injection tool for your classes when using Fast API Benefits The main benefit is being able to separate your bu

API Simples com python utilizando a biblioteca FastApi
API Simples com python utilizando a biblioteca FastApi

api-fastapi-python API Simples com python utilizando a biblioteca FastApi Para rodar esse script são necessárias duas bibliotecas: Fastapi: Comando de

Owner
Carlos Neto
DevOps | IaC | Python Developer
Carlos Neto
A simple Blogging Backend app created with Fast API

This is a simple blogging app backend built with FastAPI. This project is created to simulate a real CRUD blogging system. It is built to be used by s

Owusu Kelvin Clark 13 Mar 24, 2022
Keycloack plugin for FastApi.

FastAPI Keycloack Keycloack plugin for FastApi. Your aplication receives the claims decoded from the access token. Usage Run keycloak on port 8080 and

Elber 4 Jun 24, 2022
An alternative implement of Imjad API | Imjad API 的开源替代

HibiAPI An alternative implement of Imjad API. Imjad API 的开源替代. 前言 由于Imjad API这是什么?使用人数过多, 致使调用超出限制, 所以本人希望提供一个开源替代来供社区进行自由的部署和使用, 从而减轻一部分该API的使用压力 优势

Mix Technology 450 Dec 29, 2022
Run your jupyter notebooks as a REST API endpoint. This isn't a jupyter server but rather just a way to run your notebooks as a REST API Endpoint.

Jupter Notebook REST API Run your jupyter notebooks as a REST API endpoint. This isn't a jupyter server but rather just a way to run your notebooks as

Invictify 54 Nov 4, 2022
Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Beyonic API Python Examples. The beyonic APIs Doc Reference: https://apidocs.beyonic.com/ To start using the Beyonic API Python API, you need to start

Harun Mbaabu Mwenda 46 Sep 1, 2022
Practice-python is a simple Fast api project for dealing with modern rest api technologies.

Practice Python Practice-python is a simple Fast api project for dealing with modern rest api technologies. Deployment with docker Go to the project r

null 0 Sep 19, 2022
MS Graph API authentication example with Fast API

MS Graph API authentication example with Fast API What it is & does This is a simple python service/webapp, using FastAPI with server side rendering,

Andrew Hart 4 Aug 11, 2022
api versioning for fastapi web applications

fastapi-versioning api versioning for fastapi web applications Installation pip install fastapi-versioning Examples from fastapi import FastAPI from f

Dean Way 472 Jan 2, 2023
api versioning for fastapi web applications

fastapi-versioning api versioning for fastapi web applications Installation pip install fastapi-versioning Examples from fastapi import FastAPI from f

Dean Way 127 Feb 17, 2021
Cookiecutter API for creating Custom Skills for Azure Search using Python and Docker

cookiecutter-spacy-fastapi Python cookiecutter API for quick deployments of spaCy models with FastAPI Azure Search The API interface is compatible wit

Microsoft 379 Jan 3, 2023