diff --git a/.gitignore b/.gitignore index 042bca0..c1d688f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ public_keys/ *.facts /*.yml !/site.yml +!/hosts.yml diff --git a/ansible.cfg b/ansible.cfg index 7c16196..b00aeb1 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -2,6 +2,6 @@ ask_vault_pass = True force_handlers = True -inventory = ./hosts +inventory = ./hosts.py nocows = True retry_files_enabled = False diff --git a/hosts b/hosts deleted file mode 100644 index fc9ad8f..0000000 --- a/hosts +++ /dev/null @@ -1,19 +0,0 @@ -[bootstrap] -nvak.banananet.work -morska.banananet.work -rurapenthe.banananet.work -hardie.khitomer.banananet.work - -[public_available] -nvak.banananet.work -morska.banananet.work -rurapenthe.banananet.work - -[bwcloud_vserver] -morska.banananet.work -rurapenthe.banananet.work - -[wireguard_backbones] -nvak.banananet.work -morska.banananet.work -rurapenthe.banananet.work diff --git a/hosts.py b/hosts.py new file mode 100755 index 0000000..63b239c --- /dev/null +++ b/hosts.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import json +import sys +import yaml + +def parse(path): + with open(path, 'r') as stream: + try: + data = yaml.safe_load(stream) + except yaml.YAMLError as e: + return AnsibleError(e) + ret = { "all": { "hosts": list(), "vars": dict(), "children": list() } , "_meta": { "hostvars": {} } } + for host, groups in data.items(): + ret["all"]["hosts"].append(host) + if groups is not None: + for group in groups: + if not group in ret: + ret[group] = dict() + ret[group]["hosts"] = list() + ret[group]["vars"] = dict() + ret[group]["children"] = list() + if not host in ret[group]["hosts"]: + ret[group]["hosts"].append(host) + return ret + +print(parse("hosts.yml")) diff --git a/hosts.yml b/hosts.yml new file mode 100644 index 0000000..5f3c72b --- /dev/null +++ b/hosts.yml @@ -0,0 +1,16 @@ +nvak.banananet.work: + - bootstrap + - public_available + - wireguard_backbones +morska.banananet.work: + - bwcloud_vserver + - bootstrap + - public_available + - wireguard_backbones +rurapenthe.banananet.work: + - bwcloud_vserver + - bootstrap + - public_available + - wireguard_backbones +hardie.khitomer.banananet.work: + - bootstrap