-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexecutor.py
66 lines (56 loc) · 1.68 KB
/
executor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
import shutil
import ansible.constants as C
from ansible.executor.task_queue_manager import TaskQueueManager
from ansible.module_utils.common.collections import ImmutableDict
from ansible.inventory.manager import InventoryManager
from ansible.parsing.dataloader import DataLoader
from ansible.vars.manager import VariableManager
from ansible import context
from ansible.executor.playbook_executor import PlaybookExecutor
import os
from ansible.utils.display import Display
import getpass
loader = DataLoader()
context.CLIARGS = ImmutableDict(
listtasks=False,
listhosts=False,
syntax=False,
connection="smart",
forks=10,
become=False,
verbosity=4,
check=False,
start_at_task=None,
become_method="sudo",
become_user=None,
become_ask_pass=True,
)
host_list = ["localhost"]
sources = ",".join(host_list)
inventory = InventoryManager(loader=loader, sources=sources, cache=False)
variable_manager = VariableManager(loader=loader, inventory=inventory)
sudo_password = getpass.getpass("Enter your root password :")
passwords = dict(become_pass=sudo_password)
tqm = TaskQueueManager(
inventory=inventory,
variable_manager=variable_manager,
loader=loader,
passwords=passwords,
)
display = Display()
display.verbosity = 1
playbook_executor = PlaybookExecutor(
playbooks=[os.path.join(os.path.dirname(os.path.abspath(__file__)), "one_installer.yml")],
inventory=inventory,
variable_manager=variable_manager,
loader=loader,
passwords=passwords,
)
try:
results = playbook_executor.run()
finally:
tqm.cleanup()
if loader:
loader.cleanup_all_tmp_files()
shutil.rmtree(C.DEFAULT_LOCAL_TMP, True)