From e5c8dfe83e321c8e78f4f8e808a00285ee98402b Mon Sep 17 00:00:00 2001 From: Von Random Date: Wed, 25 Sep 2024 16:08:21 +0300 Subject: [PATCH] use bash instead of python to simplify things --- mkinv | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/mkinv b/mkinv index 9efc049..e1652e5 100755 --- a/mkinv +++ b/mkinv @@ -1,20 +1,9 @@ -#!/usr/bin/env python3 -import sys +#!/usr/bin/env bash +FILENAME="./inventory.ini" -FILENAME = "./inventory.ini" - - -def main(): - hosts = [] - counter = 0 - for addr in sys.argv[1:]: - hosts.append(f"vm{counter} ansible_host={addr}") - counter += 1 - - inventory = "\n".join(hosts) - with open(FILENAME, "w", encoding="utf8") as inv_file: - inv_file.write(inventory + "\n") - - -if __name__ == "__main__": - main() +counter=0 +echo -n > "$FILENAME" +for i; do + echo "vm$counter ansible_host=$i" >> "$FILENAME" + ((counter++)) +done