blob: 0458dc08e31dc64cdc3683605bd2f6e3d542df84 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#!/usr/bin/env python3
"""Dynamic inventory script that discovers jails from roles/jails/."""
import json
import os
import re
def main():
# Resolve to project root (one level up from inventory/)
script_dir = os.path.dirname(os.path.realpath(__file__))
project_root = os.path.dirname(script_dir)
jails_dir = os.path.join(project_root, "roles", "jails")
hosts = []
if os.path.isdir(jails_dir):
for entry in sorted(os.listdir(jails_dir)):
path = os.path.join(jails_dir, entry)
if os.path.isdir(path) and re.match(r"^\d+_", entry):
name = re.sub(r"^\d+_", "", entry)
hosts.append(name)
inventory = {
"jails": {
"hosts": hosts,
},
"_meta": {
"hostvars": {},
},
}
print(json.dumps(inventory))
if __name__ == "__main__":
main()
|