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.
Go to file
Tobias Diekershoff 5c45fc46c5
All checks were successful
continuous-integration/drone/push Build is passing
added dnl2
2024-10-04 14:30:59 +02:00
.drone.yml adding drone CI for docs sync 2023-01-13 13:45:50 +01:00
.gitignore Initial commit 2021-01-05 14:05:39 +00:00
generate_inventory drop unneeded list comprehension 2021-02-25 15:07:05 +01:00
inventory.txt added dnl2 2024-10-04 14:30:59 +02:00
LICENSE Initial commit 2021-01-05 14:05:39 +00:00
README.md touching the README 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