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

View file

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