add template extraction
All checks were successful
Deploy Containers / Prepare (push) Successful in 4s
All checks were successful
Deploy Containers / Prepare (push) Successful in 4s
This commit is contained in:
29
scripts/extract_to_template.py
Normal file
29
scripts/extract_to_template.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
host_vars_path = os.path.abspath('host_vars')
|
||||
file_contents = ""
|
||||
|
||||
if os.path.exists(host_vars_path):
|
||||
vaults = os.listdir(host_vars_path)
|
||||
|
||||
print(vaults)
|
||||
for vault in vaults:
|
||||
vault_path = os.path.join(host_vars_path, vault)
|
||||
print(f'ansible-vault decrypt "{vault_path}" --vault-password-file ~/.vault_pass.txt')
|
||||
vault_contents = subprocess.run(f'ansible-vault decrypt "{vault_path}" --vault-password-file ~/.vault_pass.txt --output -', shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
|
||||
stdout = vault_contents.stdout.strip().splitlines()
|
||||
|
||||
for line in stdout:
|
||||
if line.startswith("#") and line not in file_contents:
|
||||
file_contents += f"\n{line}\n"
|
||||
|
||||
if ":" in line:
|
||||
if line.split(":")[0] not in file_contents:
|
||||
file_contents += f'{line.split(":")[0]}:\n'
|
||||
|
||||
with open(os.path.join(host_vars_path, 'all.template.yml'), 'w', encoding="utf8") as template_file:
|
||||
template_file.write(file_contents)
|
||||
template_file.close()
|
||||
|
||||
print("Written to disk!")
|
||||
Reference in New Issue
Block a user