Ansible

From WTFwiki
Revision as of 18:05, 15 March 2023 by Stian (talk | contribs) (Created page with "== Script for testing template things == #!/usr/bin/python3 import os import sys from ansible.inventory.helpers import get_group_vars from ansible.inventory.manager...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Script for testing template things

#!/usr/bin/python3

import os
import sys

from ansible.inventory.helpers import get_group_vars
from ansible.inventory.manager import InventoryManager
from ansible.parsing.dataloader import DataLoader
from ansible.template import Templar
from ansible.vars.manager import VariableManager

BASE_DIR = os.path.expanduser('~/ansible')
INVENTORY_FILE = 'inventory.ini'


os.chdir(BASE_DIR)

loader = DataLoader()
inventory = InventoryManager(loader=loader, sources=[INVENTORY_FILE])
variable_manager = VariableManager(loader=loader, inventory=inventory)
templar = Templar(loader=loader, variables=variable_manager.get_vars())

r = templar.template(sys.argv[1])
print(r)