]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
minor optimizations, included OS facts and dns_options (resolv.conf)
authorVeselin Bochev <veselin.bochev@WKMZT0869FF7.global.publicisgroupe.net>
Wed, 1 Jun 2022 13:51:56 +0000 (16:51 +0300)
committerVeselin Bochev <veselin.bochev@WKMZT0869FF7.global.publicisgroupe.net>
Wed, 1 Jun 2022 13:51:56 +0000 (16:51 +0300)
bin/pre-terraform

index 71a5ac6cbc1cb06b90d8f655a964fcb5ecd8a033..1f3aae382e4c4d8e99f3bcf3232721139c55c909 100755 (executable)
@@ -92,15 +92,15 @@ for fact in facts:
 sample_pre_tf = {
     "defaults": {
         "vsphere": "live",
-        "cluster": "vmcc-l105-01",
-        "vm_folder": "Pixelpark/__",
+        "cluster": "vmcc-l105-01                                <<< Check this",
+        "vm_folder": "Pixelpark/__                              <<< Check this",
         "num_cpus": 0,
         "memory": "__",
         "boot_delay": 5,
-        "template": "__",
+        "template": "__                                         <<< Check this",
         "customer": "__",
         "purpose": "__",
-        "datastore_cluster": "ds-cluster-hdd-vmcc-l105-01",
+        "datastore_cluster": "ds-cluster-hdd-vmcc-l105-01       <<< Check this",
         "datastore_type": "sata",
         "root_disk": { "size": 0 },
         "data_disks": [],
@@ -124,6 +124,8 @@ sample_pre_tf = {
 }
 
 try:
+    print(f"OS according to facts: {data['os']['value']['name']} {data['os']['value']['release']['full']}\n")
+
     # Nameservers resolv.conf
     for ns in data["resolv_conf"]["value"]["nameserver"]:
         sample_pre_tf["defaults"]["namservers"].append(ns)
@@ -132,9 +134,20 @@ try:
     for sd in data["resolv_conf"]["value"]["search"]:
         sample_pre_tf["defaults"]["searchdomains"].append(sd)
 
+    # Options resolv.conf
+    try:
+        timeout = data["resolv_conf"]["value"]["timeout"]
+        attempts = data["resolv_conf"]["value"]["attempts"]
+    except:
+        timeout = 1
+        attempts = 2
+
+    sample_pre_tf["defaults"]["dns_options"] = f"timeout: {timeout} attempts: {attempts}"
+
     # Disks root
     sample_pre_tf["defaults"]["root_disk"]["size"] = int(data["disks"]["value"]["sda"]["size_bytes"]/int(1<<30))
-    # additional disks
+
+    # Disks additional
     for disk in data["disks"]["value"]:
         if disk.startswith("sd") and disk != "sda":
             sample_pre_tf["defaults"]["data_disks"].append(
@@ -179,9 +192,16 @@ except:
     print("ERROR: Failed parsing required fields from output. Please check if hostname is in PuppetDB")
     _exit(1)
 
-print(yaml.dump(sample_pre_tf))
+# Print the YAML configuration file
+print(f"Template:\n---\n{yaml.dump(sample_pre_tf)}")
 
 __author__ = 'Veselin Bochev <veselin.bochev@pixelpark.com>'
 __copyright__ = '(C) 2022 by Veselin Bochev, Pixelpark GmbH, Berlin'
 
-# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 
+# These are the facts - Slim version
+# print(data)
+
+# These are the facts - All
+# print(facts)
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 
\ No newline at end of file