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:[email protected]: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                                                                     
Owner
Carlos Neto
DevOps | IaC | Python Developer
Carlos Neto
Generate modern Python clients from OpenAPI

openapi-python-client Generate modern Python clients from OpenAPI 3.x documents. This generator does not support OpenAPI 2.x FKA Swagger. If you need

Triax Technologies 558 Jan 07, 2023
A FastAPI Middleware of joerick/pyinstrument to check your service performance.

fastapi_profiler A FastAPI Middleware of joerick/pyinstrument to check your service performance. 📣 Info A FastAPI Middleware of pyinstrument to check

LeoSun 107 Jan 05, 2023
Dead-simple mailer micro-service for static websites

Mailer Dead-simple mailer micro-service for static websites A free and open-source software alternative to contact form services such as FormSpree, to

Romain Clement 42 Dec 21, 2022
Repository for the Demo of using DVC with PyCaret & MLOps (DVC Office Hours - 20th Jan, 2022)

Using DVC with PyCaret & FastAPI (Demo) This repo contains all the resources for my demo explaining how to use DVC along with other interesting tools

Tezan Sahu 6 Jul 22, 2022
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

Leonardo Grava 0 Apr 29, 2022
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
Opentracing support for Starlette and FastApi

Starlette-OpenTracing OpenTracing support for Starlette and FastApi. Inspired by: Flask-OpenTracing OpenTracing implementations exist for major distri

Rene Dohmen 63 Dec 30, 2022
Adds simple SQLAlchemy support to FastAPI

FastAPI-SQLAlchemy FastAPI-SQLAlchemy provides a simple integration between FastAPI and SQLAlchemy in your application. It gives access to useful help

Michael Freeborn 465 Jan 07, 2023
Sample project showing reliable data ingestion application using FastAPI and dramatiq

Create and deploy a reliable data ingestion service with FastAPI, SQLModel and Dramatiq This is the source code for the data ingestion service explain

François Voron 31 Nov 30, 2022
A rate limiter for Starlette and FastAPI

SlowApi A rate limiting library for Starlette and FastAPI adapted from flask-limiter. Note: this is alpha quality code still, the API may change, and

Laurent Savaete 562 Jan 01, 2023
API written using Fast API to manage events and implement a leaderboard / badge system.

Open Food Facts Events API written using Fast API to manage events and implement a leaderboard / badge system. Installation To run the API locally, ru

Open Food Facts 5 Jan 07, 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 472 Jan 02, 2023
Docker Sample Project - FastAPI + NGINX

Docker Sample Project - FastAPI + NGINX Run FastAPI and Nginx using Docker container Installation Make sure Docker is installed on your local machine

1 Feb 11, 2022
Prometheus exporter for several chia node statistics

prometheus-chia-exporter Prometheus exporter for several chia node statistics It's assumed that the full node, the harvester and the wallet run on the

30 Sep 19, 2022
A minimal FastAPI implementation for Django !

Caution!!! This project is in early developing stage. So use it at you own risk. Bug reports / Fix PRs are welcomed. Installation pip install django-m

toki 23 Dec 24, 2022
FastAPI client generator

FastAPI-based API Client Generator Generate a mypy- and IDE-friendly API client from an OpenAPI spec. Sync and async interfaces are both available Com

David Montague 283 Jan 04, 2023
Reusable utilities for FastAPI

Reusable utilities for FastAPI Documentation: https://fastapi-utils.davidmontague.xyz Source Code: https://github.com/dmontagu/fastapi-utils FastAPI i

David Montague 1.3k Jan 04, 2023
User authentication fastapi with python

user-authentication-fastapi Authentication API Development Setup environment You should create a virtual environment and activate it: virtualenv venv

Sabir Hussain 3 Mar 03, 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

0 Sep 19, 2022
flask extension for integration with the awesome pydantic package

flask extension for integration with the awesome pydantic package

249 Jan 06, 2023