This repo holds custom callback plugin, so your Ansible could write everything in the PostgreSQL database.

Overview

English

What is it?

This is callback plugin that dumps most of the Ansible internal state to the external PostgreSQL database.

What is this for?

If you ever had to:

  • know the value of the certain variable before the role or task starts;
  • implement an audit soultion which should send data to some remote storage for unchangeability;
  • investigate into some Ansible function while dreaming of looking under the hood

...then this plugin is right for you.

Requirements

  • CentOS/RHEL 7.x;
  • Ansible 2.9.x;
  • Python >=3.6.x;
  • PostgreSQL >=10.x (this was debugged with Postgres 12, though)

Quick start guide

  1. Copy to your project directory:
    1. playbooks/callback_plugins/logdb.py
    2. playbooks/module_utils/pg8000/*
    3. playbooks/module_utils/scramp/*
  2. Add settings to the ansible.cfg as follows:
[defaults]
stdout_callback = log2db
callable_plugins = log2db
callback_whitelist = log2db

[log2db_callback]
host = <your PostgreSQL server hostname>
port = <your PostgreSQL server port, usually 5432>
user = <database account with insert privilege>
pass = <database account password>
db = <database name, default is "ansible">
table = <table name, default is "logs">
  1. Do not forget to setup a database and a table before the first launch. Also, an account with proper rights is a must:
[[email protected]]> sudo -u postgres psql
postgres=# CREATE DATABASE <my_db_name> WITH OWNER postgres;
postgres=# CREATE USER <my_db_user>;
postgres=# GRANT CONNECT, CREATE, TEMPORARY ON DATABASE <my_db_name> to <my_db_user>;
postgres=# CREATE TABLE IF NOT EXISTS <my_table_name> (
   uuid uuid not null,
   data jsonb,
   timestamp timestamp with time zone,
   id bigserial
   constraint logs_pk
   primary key,
   origin text);
postgres=# ALTER TABLE <my_table_name> OWNER to <my_db_account>;
postgres=# CREATE INDEX IF NOT EXISTS <my_table_name>_uuid_index on <my_table_name> (uuid);
postgres=# ALTER USER <my_db_user> WITH PASSWORD '<my_db_password>';

How to send a donation to the author

If you want to thank the author - this is a donate link. Any sum is happily accepted.

Legal information

This project is conceived and performed by me, Sergey Pechenko, on my own will, out of working hours, using own hardware.

Copyright: (С) 2021, Sergey Pechenko

Based on "default.py" callback plugin for Ansible, which has own copyrights:

(C) 2012-2014, Michael DeHaan [email protected]

(C) 2017 Ansible Project

This project uses MIT-licensed components as follows:

  • pg8000 (c) 2007-2009, Mathieu Fenniak

  • scramp (C) 2019 Tony Locke

Portions for these components that provide possibility for Ansible to load and run them are also (C) 2021, Sergey Pechenko.

License

GPLv3+ (please see LICENSE)

Contact

You can ask your questions about this plugin at the Ansible chat, or PM me

Русский

Что это?

Коллбэк-плагин для Ansible, который позволяет сохранять бОльшую часть внутренних данных Ansible во внешнюю БД.

Зачем это?

Если тебе когда-нибудь:

  • требовалось при отладке знать значение конкретной переменной перед исполнением таска или вызовом роли;
  • приходилось организовывать аудит с сохранением данных в отдельном от Ansible внешнем хранилище;
  • случалось разбираться с какой-то функций Ansible в мечтах о возможности "заглянуть под капот" -

...то этот плагин - для тебя.

Что требуется?

  • CentOS/RHEL 7.x;
  • Ansible 2.9.x;
  • Python >=3.6.x;
  • PostgreSQL >=10 (отлаживалось на 12);

Как запустить?

  1. Скопируй в каталог с проектом:
    1. playbooks/callback_plugins/logdb.py
    2. playbooks/module_utils/pg8000/*
    3. playbooks/module_utils/scramp/*
  2. Укажи в ansible.cfg следующее:
[defaults]
stdout_callback = logdb
callable_plugins = logdb
callback_whitelist = logdb

[logdb_callback]
host = <имя хоста PostgreSQL>
port = <порт сервера PostgreSQL, обычно 5432>
user = <учётная запись в БД с правами на INSERT>
pass = <пароль этой учётной записи>
db = <название БД, по умолчанию "ansible">
table = <название таблицы, по умолчанию "logs">
  1. Перед запуском не забудь создать БД и таблицу. А ещё понадобится создать учётку и дать ей права:
[[email protected]]> sudo -u postgres psql
postgres=# CREATE DATABASE <название БД> WITH OWNER postgres;
postgres=# CREATE USER <учётная запись>;
postgres=# GRANT CONNECT, CREATE, TEMPORARY ON DATABASE <название БД> to <учётная запись>;
postgres=# CREATE TABLE IF NOT EXISTS <название таблицы> (
   uuid uuid not null,
   data jsonb,
   timestamp timestamp with time zone,
   id bigserial
   constraint logs_pk
   primary key,
   origin text);
postgres=# ALTER TABLE <название таблицы> OWNER to <учётная запись>;
postgres=# CREATE INDEX IF NOT EXISTS <название таблицы>_uuid_index on <название таблицы> (uuid);
postgres=# ALTER USER <учётная запись> WITH PASSWORD '<пароль учётной записи>';

Поблагодарить автора

Если хочешь поблагодарить автора - вот ссылка для донатов. Буду рад любой сумме.

Правовая информация

Этот проект задуман и выполнен мною, Сергеем Печенко, по личной инициативе в нерабочее время на личном оборудовании.

Авторские права: (С) 2021, Sergey Pechenko

Проект выполнен на основе коллбэк-плагина "default.py" для Ansible. Авторские права на оригинальный файл:

(C) 2012-2014, Michael DeHaan [email protected]

(C) 2017 Ansible Project

При создании проекта по лицензии MIT использованы следующие компоненты:

  • pg8000 (C) Mathieu Fenniak
  • scramp (C) Tony Locke

Авторские права на части этих компонентов, обеспечивающие Ansible возможность их загрузки и выполнения: (С) 2021, Сергей Печенко

Лицензия

GPLv3+

Контакты

Можешь задать свои вопросы в чате по Ansible, или написать мне в ЛС.

Owner
Sergey Pechenko
Sergey Pechenko
Random Turkish name generator with realistic probabilities.

trnames Random Turkish name generator with realistic probabilities. Based on Trey Hunner's names package. Installation The package can be installed us

Kaan Öztürk 20 Jan 02, 2023
World's best free and open source ERP.

World's best free and open source ERP.

Frappe 12.5k Jan 07, 2023
This script provides LIVE feedback for On-The-Fly data collection with RELION

README This script provides LIVE feedback for On-The-Fly data collection with RELION (very useful to explore already processed datasets too!) Creating

cryoEM CNIO 6 Jul 14, 2022
Pdraw - Generate Deterministic, Procedural Artwork from Arbitrary Text

pdraw.py: Generate Deterministic, Procedural Artwork from Arbitrary Text pdraw a

Brian Schrader 2 Sep 12, 2022
The fundamentals of Python!

The fundamentals of Python Author: Mohamed NIANG, Staff ML Scientist Presentation This repository contains notebooks on the fundamentals of Python. Th

Mohamed NIANG 1 Mar 15, 2022
This synchronizes my appearances with my calendar

Josh's Schedule Synchronizer Here's the "problem:" I use a Google Sheets spreadsheet to maintain all my public appearances.

Developer Advocacy 2 Oct 18, 2021
Demodulate and error correct FIS-B and ADS-B signals on 978 MHz.

FIS-B 978 ('fisb-978') is a set of programs that demodulates and error corrects FIS-B (Flight Information System - Broadcast) and ADS-B (Automatic Dep

2 Nov 15, 2022
👀 nothing to see here

Woofy Woofy is blue dog companion token of YFI (Wifey) It utilizes a special Woof bonding curve which allows two-way conversion between the tokens. Th

Yearn Finance 36 Mar 14, 2022
Code repo for the book "Feature Engineering for Machine Learning," by Alice Zheng and Amanda Casari, O'Reilly 2018

feature-engineering-book This repo accompanies "Feature Engineering for Machine Learning," by Alice Zheng and Amanda Casari. O'Reilly, 2018. The repo

Alice Zheng 1.3k Dec 30, 2022
Python Monopoly Simulator

Monopoly simulator Original creator: Games Computer Play YouTube: https://www.youtube.com/channel/UCTrp88f-QJ1SqKX8o5IDhWQ Config file (optional) conf

Games Computers Play 37 Jan 03, 2023
Create a program for generator Truth Table

Python-Truth-Table-Ver-1.0 Create a program for generator Truth Table in here you have to install truth-table-generator module for python modules inst

JehanKandy 10 Jul 13, 2022
YourX: URL Clusterer With Python

YourX | URL Clusterer Screenshots Instructions for running Install requirements

ARPSyndicate 1 Mar 11, 2022
Construção de um jogo Dominó na linguagem python com base em algoritmos personalizados.

Domino (projecto-python) Construção de um jogo Dominó na linguaguem python com base em algoritmos personalizados e na: Monografia apresentada ao curso

Nuninha-GC 1 Jan 12, 2022
🦋 hundun is a python library for the exploration of chaos.

hundun hundun is a python library for the exploration of chaos. Please note that this library is in beta phase. Example Import the package's equation

kosh 7 Nov 07, 2022
A New, Interactive Approach to Learning Python

This is the repository for The Python Workshop, published by Packt. It contains all the supporting project files necessary to work through the course from start to finish.

Packt Workshops 231 Dec 26, 2022
A simple language for new programmers and a toy language ;)

Yell An extremely simple, yet powerful language for new programmers, as well as a toy language ;) Explore the docs » Report Bug · Request Feature Yell

Yell 4 Dec 28, 2021
The program converts Swiss notes into American notes

Informatik-Programmieren Einleitung: Das Programm rechnet Schweizer Noten in das Amerikanische Noten um. Der Benutzer kann seine Note eingeben und der

2 Dec 16, 2021
Library for RadiaCode-101

RadiaCode Библиотека для работы с дозиметром RadiaCode-101, находится в разработке - API не стабилен и возможны изменения. Пример использования (backe

Maxim Andreev 56 Nov 29, 2022
Alerts for Western Australian Covid-19 exposure locations via email and Slack

WA Covid Mailer Sends alerts from Healthy WA's Covid19 Exposure Locations via email and slack. Setup Edit the configuration items in wacovidmailer.py

13 Mar 29, 2022
This is a working model for which I have used python.

Jarvis_voiceAssistance This is a working model for which I have used python. This model can: 1)Play a video or song on youtube. 2)Tell us time. 3)Tell

Hardik Jain 1 Jan 30, 2022