Skip to main content

git based config files manager and installer

Project description

cfg : git based config files manager and installer
==================================================

This command line tool helps you to keep your customized system configuration files in a
git repository.

Installation
------------

In addition of python3 and related modules, cfg depends of these binaries:

- git
- colordiff

Latest release could be installed via::

pip3 install cfg-manager

Or frome these sources::

sudo setup.py install

Quickstart
----------

A *cfg* based project is basically composed of:

- a *git* repository with a ``src`` directory where your customized configuration files
are located, for example::

src/etc/aliases
src/etc/apache2/ports.conf
...

- a ``cfg_params.py`` file with at least the *TARGET* parameter set, for example::

TARGET = "/"

Once *TARGET* parameter is configured, you can add existing config file with::

cfg add /etc/postfix/main.cf

The previous command will create ``src/etc/postfix/main.cf`` file and commit it to the
repository. Don't forget to ``git push`` your work.

To see if your ``src`` and target directory differs, do a::

cfg check

It will compare the two directories and eventually output differences::

checking content...
/etc/aliases :
2a3
> root: f@idez.net

And then::

cfg install

Will install the modified files, producing the same output. Original dest files are
backed up with ``.old`` extension.

Template files
--------------

For multiple environments usage (duplicated servers, sub-configurations), a pattern
substitution system is provided:

For example let's say you have in your ``cfg_params.py``:

.. code-block:: python

import socket
import sys
HOSTNAME = socket.gethostname()
if HOSTNAME == "master-kf":
TARGET = "/"
HOST_IP = "5.223.34.110"
PEER_IP = "5.68.252.23"
elif HOSTNAME == "backup-kf":
TARGET = "/"
HOST_IP = "5.68.252.23"
PEER_IP = "5.223.34.110"
elif HOSTNAME == "bic":
TARGET = "/home/fredz/tmp/dst_cfg"
HOST_IP = "127.0.0.1"
PEER_IP = "666.666.666.666"
else:
print("cfg_params.py : uknown host :", HOSTNAME)
sys.exit(0)

If you want to use these parameters in one of your config files, let's say ``/etc/keepalived/keepalived.conf``:

1. add it to your repo with ``cfg add``,
2. rename it to ``/etc/keepalived/cfg.keepalived.conf``
3. use ``cfg[PATTERN]`` in your file:

.. code-block:: squid

vrrp_instance VI_1 {
state BACKUP
interface ens3
unicast_src_ip =cfg[HOST_IP]
unicast_peer {
=cfg[PEER_IP]
}

virtual_router_id 101
priority 101
advert_int 4
nopreempt
virtual_ipaddress {
666.999.999.666
}
notify /usr/local/bin/ovh_ip_up.py
}

Notes:

- As shown in previous example, you can use python code to face various environment
configurations.
- **Only uppercase parameters names are exported**.

Per-host files
--------------

When configuration files are too different, you can provide host-dedicated versions of
config files : simply prefix desired filenames with "cfg-[HOSTNAME]." where [HOSTNAME] is
the target *hostname*. For example:

src/etc/cfg-bic.aliases


Permissions
-----------

Because git repositories only handle executable flag permissions,target files
permissions are preserved. It is the more simple and safe approach because most of the
times, target files already exists.

In a future release, I could had *in repository* permission management, but I have no
simple approach yet.


Internals
---------

For safety and fast processing, src and target directories files contents are compared
using git hashes:
- pre-computed src git sha1 hashes for src
- ``git hash-object --stdin-paths`` for src, in one system call.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cfg-manager-1.1.5.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

cfg_manager-1.1.5-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file cfg-manager-1.1.5.tar.gz.

File metadata

  • Download URL: cfg-manager-1.1.5.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/38.4.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.7

File hashes

Hashes for cfg-manager-1.1.5.tar.gz
Algorithm Hash digest
SHA256 3537ea8e08bf9f329ecb3f7ef19cf52b2f1f71299bde8e20f0a8ba33ef057197
MD5 f31c1ee6584f0c90cb6ba09fb38e9f9f
BLAKE2b-256 8b2aad3ce52bf90a51f2d3e1df6ba064a90b7d4365d8a4f7eddd434b51a21644

See more details on using hashes here.

File details

Details for the file cfg_manager-1.1.5-py3-none-any.whl.

File metadata

  • Download URL: cfg_manager-1.1.5-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/38.4.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.7

File hashes

Hashes for cfg_manager-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 88ea31010bf3e3ae255aeeaf15a85f982ffec494b4494ecdb7b3bb526ea945fe
MD5 e257c0975e543a70b15f3d356fa51f3f
BLAKE2b-256 1245c83a7b4e246e4b06c95c6d61aca752a8e1403b9faf52b7e9c3fb9f80589e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page