Tobias Diekershoff 9dc978ce6f
All checks were successful
continuous-integration/drone/push Build is passing
added ulloa
2025-04-07 16:39:30 +02:00
2023-01-13 13:45:50 +01:00
2021-01-05 14:05:39 +00:00
2025-04-07 16:39:30 +02:00
2021-01-05 14:05:39 +00:00
2024-03-11 11:51:23 +01:00

Ansible Inventory

A unified plaintext store (inventory.txt) of all of our hosts that are managed with Ansible. Supposed to be integrated into the relevant Ansible repos as a git submodule.

in docs.fsfe.org

How it works

It is simple. The Python script generate_inventory reads the lines from inventory.txt and constructs a well-defined Ansible inventory file for all our hosts from it. This is handy because it allows for a more streamlined adding, removing and changing of hosts and the groups that they are in.

Adding a host

inventory.txt has the following structure. To add a new host, simply add a new line starting with - followed by a space, then the hostname and then the applicable groups in square brackets.

To illustrate, generate_inventory` would take the input below:

# some comment
- example.fsfe.org [group1, group2, group3, group4]
- example2.fsfe.org [group1, group5]

and would then return the following as standard output:

{
  "group1": {
    "hosts": [
      "example.fsfeurope.org",
      "example2.fsfeurope.org",
    ]
  },
  "group2": {
    "hosts": [
      "example.fsfeurope.org",
    ]
  },
  "group3": {
    "hosts": [
      "example.fsfeurope.org",
    ]
  },
  "group4": {
    "hosts": [
      "example.fsfeurope.org",
    ]
  },
  "group5": {
    "hosts": [
      "example2.fsfeurope.org",
    ]
  }
}

Possible future improvements

  • Make script more robust to, for example, allow for comments in inventory.txt
  • Create CLI to remove, update and add hosts and groups
  • Add the ability to store some host_vars should the need arise (Currently, we do this in the repos where the playbooks are)

Resources

Description
A unified plaintext store of all fsfe hosts that are managed with Ansible. Supposed to be integrated into the relevant repos as a git submodule.
Readme GPL-3.0 170 KiB
Languages
Python 100%