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
Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.

The Mixer is a helper to generate instances of Django or SQLAlchemy models. It's useful for testing and fixture replacement. Fast and convenient test-

Kirill Klenov 871 Dec 25, 2022
Learn to deploy a FastAPI application into production DigitalOcean App Platform

Learn to deploy a FastAPI application into production DigitalOcean App Platform. This is a microservice for our Try Django 3.2 project. The goal is to extract any and all text from images using a tec

Coding For Entrepreneurs 59 Nov 29, 2022
Adds GraphQL support to your Flask application.

Flask-GraphQL Adds GraphQL support to your Flask application. Usage Just use the GraphQLView view from flask_graphql from flask import Flask from flas

GraphQL Python 1.3k Dec 31, 2022
Prometheus integration for Starlette.

Starlette Prometheus Introduction Prometheus integration for Starlette. Requirements Python 3.6+ Starlette 0.9+ Installation $ pip install starlette-p

José Antonio Perdiguero 229 Dec 21, 2022
FastAPI application and service structure for a more maintainable codebase

Abstracting FastAPI Services See this article for more information: https://camillovisini.com/article/abstracting-fastapi-services/ Poetry poetry inst

Camillo Visini 309 Jan 04, 2023
Generate Class & Decorators for your FastAPI project ✨🚀

Classes and Decorators to use FastAPI with class based routing. In particular this allows you to construct an instance of a class and have methods of that instance be route handlers for FastAPI & Pyt

Yasser Tahiri 34 Oct 27, 2022
This repository contains learning resources for Python Fast API Framework and Docker

This repository contains learning resources for Python Fast API Framework and Docker, Build High Performing Apps With Python BootCamp by Lux Academy and Data Science East Africa.

Harun Mbaabu Mwenda 23 Nov 20, 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
Utils for fastapi based services.

Installation pip install fastapi-serviceutils Usage For more details and usage see: readthedocs Development Getting started After cloning the repo

Simon Kallfass 31 Nov 25, 2022
Cache-house - Caching tool for python, working with Redis single instance and Redis cluster mode

Caching tool for python, working with Redis single instance and Redis cluster mo

Tural 14 Jan 06, 2022
Code for my FastAPI tutorial

FastAPI tutorial Code for my video tutorial FastAPI tutorial What is FastAPI? FastAPI is a high-performant REST API framework for Python. It's built o

José Haro Peralta 9 Nov 15, 2022
FastAPI CRUD template using Deta Base

Deta Base FastAPI CRUD FastAPI CRUD template using Deta Base Setup Install the requirements for the CRUD: pip3 install -r requirements.txt Add your D

Sebastian Ponce 2 Dec 15, 2021
An extension library for FastAPI framework

FastLab An extension library for FastAPI framework Features Logging Models Utils Routers Installation use pip to install the package: pip install fast

Tezign Lab 10 Jul 11, 2022
FastAPI pagination

FastAPI Pagination Installation # Basic version pip install fastapi-pagination # All available integrations pip install fastapi-pagination[all] Avail

Yurii Karabas 561 Jan 07, 2023
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 04, 2022
Dead simple CSRF security middleware for Starlette ⭐ and Fast API ⚡

csrf-starlette-fastapi Dead simple CSRF security middleware for Starlette ⭐ and Fast API ⚡ Will work with either a input type="hidden" field or ajax

Nathaniel Sabanski 9 Nov 20, 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
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 using python and Fastapi framework

Welcome 👋 CFCApi is a API DEVELOPMENT PROJECT UNDER CODE FOR COMMUNITY ! Project Walkthrough 🚀 CFCApi run on Python using FASTapi Framework Docs The

Abhishek kushwaha 7 Jan 02, 2023
FastAPI IPyKernel Sandbox

FastAPI IPyKernel Sandbox This repository is a light-weight FastAPI project that is meant to provide a wrapper around IPyKernel interactions. It is in

Nick Wold 2 Oct 25, 2021