-
Notifications
You must be signed in to change notification settings - Fork 1
/
chikuwansible-task
executable file
·46 lines (37 loc) · 1.14 KB
/
chikuwansible-task
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
#!/usr/bin/env python3
import os
import sys
import subprocess
tmp_one_task_file_name = "tmp_one_task.yml"
tmp_one_task_file = open(tmp_one_task_file_name, "a")
def help():
"""
Usage: chikuwansible-task [TASK_FILE_NAME...]
"""
print(help.__doc__)
def execute_task(task_name):
if task_name[-4:] == ".yml":
task_name = task_name[:-4]
if task_name[:6] == "tasks/":
task_name = task_name[6:]
if task_name[:8] == "./tasks/":
task_name = task_name[8:]
proc = subprocess.Popen(f"cp -a yml_template.yml {tmp_one_task_file_name}", shell=True)
proc.communicate()
s = f" - include: tasks/{task_name}.yml\n"
tmp_one_task_file.write(s)
tmp_one_task_file.flush()
proc = subprocess.Popen(f"./chikuwansible-playbook {tmp_one_task_file_name}", shell=True)
proc.communicate()
argv = sys.argv
argc = len(argv)
if argv[1] in ("-h", "--help"):
help()
exit()
for task_name in argv[1:]:
execute_task(task_name)
tmp_one_task_file.close()
os.remove(tmp_one_task_file_name)
retry_file_name = tmp_one_task_file_name[:-4] + ".retry"
if os.path.exists(retry_file_name):
os.remove(retry_file_name)