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.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Max Mehl 5c110a9543
make mail1 an innernet client
2 days ago
.gitignore Initial commit 2 years ago
LICENSE Initial commit 2 years ago
README.md changed README.md to reflect the dynamic nature of the inventory 1 year ago
generate_inventory drop unneeded list comprehension 1 year ago
inventory.txt make mail1 an innernet client 2 days ago

README.md

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.

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