1
0
Fork 0

disable gitignore, use ini inventory to avoid pyyaml

This commit is contained in:
Von Random 2024-09-25 14:45:32 +03:00
parent 9cfe1f008f
commit f0031c427e
3 changed files with 8 additions and 11 deletions

2
.gitignore vendored
View file

@ -1,2 +0,0 @@
.venv
inventory.yaml

15
mkinv
View file

@ -1,20 +1,19 @@
#!/usr/bin/env python3
import sys
import yaml
FILENAME = "./inventory.ini"
def main():
hosts = {}
hosts = []
counter = 0
for addr in sys.argv[1:]:
hosts[f"vm{counter}"] = { "ansible_host": addr }
hosts.append(f"vm{counter} ansible_host={addr}")
counter += 1
inventory = { "all": { "hosts": hosts } }
inventory_yaml = yaml.dump(inventory)
print(inventory_yaml)
# with open("./inventory.yaml", "w", encoding="utf8") as inv_file:
# inv_file.write(inventory_yaml)
inventory = "\n".join(hosts)
with open(FILENAME, "w", encoding="utf8") as inv_file:
inv_file.write(inventory + "\n")
if __name__ == "__main__":

View file

@ -18,7 +18,7 @@ http {
server {
listen 80 default_server;
location / {
return 200 ">>>>>>>>>> I am {{ inventory_hostname }} ({{ ipv4.address }}) <<<<<<<<<<\n";
return 200 ">>>>>>>>>> I am {{ inventory_hostname }} ({{ ansible_host }}) <<<<<<<<<<\n";
}
}
}