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
Collaboration project to creating bank application maded by Anzhelica Sakun and Yuriy Konyukh

Collaboration project to creating bank application maded by Anzhelica Sakun and Yuriy Konyukh

Yuriy 1 Jan 08, 2022
Flow control is the order in which statements or blocks of code are executed at runtime based on a condition. Learn Conditional statements, Iterative statements, and Transfer statements

03_Python_Flow_Control Introduction 👋 The control flow statements are an essential part of the Python programming language. A control flow statement

Milaan Parmar / Милан пармар / _米兰 帕尔马 209 Oct 31, 2022
A script to automatically update bot status at GitHub as well as in Telegram channel.

A simple & short repository to show your bot's status in your GitHub README.md file as well as in you channel.

Jainam Oswal 55 Dec 13, 2022
python scripts and other files to generate induction encoder PCBs in Kicad

induction_encoder python scripts and other files to generate induction encoder PCBs in Kicad Targeting the Renesas IPS2200 encoder chips.

Taylor Alexander 8 Feb 16, 2022
0CD - BinaryNinja plugin to introduce some quality of life utilities for obsessive compulsive CTF enthusiasts

0CD Author: b0bb Quality of life utilities for obsessive compulsive CTF enthusia

12 Sep 14, 2022
A simple script written using symbolic python that takes as input a desired metric and automatically calculates and outputs the Christoffel Pseudo-Tensor, Riemann Curvature Tensor, Ricci Tensor, Scalar Curvature and the Kretschmann Scalar

A simple script written using symbolic python that takes as input a desired metric and automatically calculates and outputs the Christoffel Pseudo-Tensor, Riemann Curvature Tensor, Ricci Tensor, Scal

2 Nov 27, 2021
API to summarize input text

summaries API to summarize input text normal run $ docker-compose exec web python -m pytest disable warnings $ docker-compose exec web python -m pytes

Brad 1 Sep 08, 2021
✨ Udemy Coupon Finder For Discord. Supports Turkish & English Language.

Udemy Course Finder Bot | Udemy Kupon Bulucu Botu This bot finds new udemy coupons and sends to the channel. Before Setup You must have python = 3.6

Penguen 4 May 04, 2022
GWAS summary statistics files QC tool

SSrehab dependencies: python 3.8+ a GNU/Linux with bash v4 or 5. python packages in requirements.txt bcftools (only for prepare_dbSNPs) gz-sort (only

21 Nov 02, 2022
an opensourced roblox group finder writen in python 100% free and virus-free

Roblox-Group-Finder an opensourced roblox group finder writen in python 100% free and virus-free note : if you don't want install python or just use w

mollomm1 1 Nov 11, 2021
An assistant to guess your pip dependencies from your code, without using a requirements file.

Pip Sala Bim is an assistant to guess your pip dependencies from your code, without using a requirements file. Pip Sala Bim will tell you which packag

Collage Labs 15 Nov 19, 2022
Check if Python package names are available on PyPI.

😻 isavailable Can I haz this Python package on PyPI? Check if Python package names are available on PyPI. Usage $ isavailable checks whether your des

Felipe S. S. Schneider 3 May 18, 2022
A code ecosystem that helps to find the equate any formula.

A code ecosystem that helps to find the equate any formula. The good part here is that the code finds the formula needed and/or operates on a formula (performs algebra) on it to give you an answer.

SubtleCoder 1 Nov 23, 2021
Python screenshot library, replacement for the Pillow ImageGrab module on Linux.

tldr: Use Pillow The pyscreenshot module is obsolete in most cases. It was created because PIL ImageGrab module worked on Windows only, but now Linux

455 Dec 24, 2022
UFDR2DIR - A script to convert a Cellebrite UFDR to the original file structure

UFDR2DIR A script to convert a Cellebrite UFDR to it's original file and directo

DFIRScience 25 Oct 24, 2022
log4shell pwner for vulnerable minecraft servers

Log4-hell name supposed to be Log4$hell but oh well log4shell pwner for vulnerable minecraft servers install all reqs python + a minecraft client for

1 Jan 05, 2022
Lectures for Udemy - Complete Python Bootcamp Course

Complete-Python-Bootcamp Welcome to the Repository for the Complete Python Bootcamp! This is the Repository for the Udemy course - "Complete Python Bo

Marci 2k Dec 28, 2022
An addin for Autodesk Fusion 360 that lets you view your design in a Looking Glass Portrait 3D display

An addin for Autodesk Fusion 360 that lets you view your design in a Looking Glass Portrait 3D display

Brian Peiris 12 Nov 02, 2022
Terminal compatible with ansi-bbs. Meant to be a prototype, but published because why not.

pybbsterm: Terminal emulator for calling BBSs. Use cases (non-exhaustive) Explore terminal protocols. Connect to BBSs. Highlights Python 3.8+ code. Bu

Roc Vallès i Domènech 9 Apr 29, 2022
Strawberry Benchmark With Python

Strawberry benchmarks these benchmarks have been made to compare the performance of dataloaders and joined database queries. How to use You can run th

Doctor 4 Feb 23, 2022