Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Commit 0e11389

Browse files
authored
Merge pull request #52 from mnecas/put_execution_to_artifatc
Allow parallel execution: put execution to artifacts
2 parents 7184e10 + 3fcbbd3 commit 0e11389

File tree

3 files changed

+17
-32
lines changed

3 files changed

+17
-32
lines changed

runner_service/configuration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class Config(object):
2929
"debug": False
3030
},
3131
"dev": {
32-
"logging_conf": "./logging.yaml",
33-
"log_path": "./",
34-
"config_file": "./config.yaml",
35-
"playbooks_root_dir": "./samples",
32+
"logging_conf": os.path.abspath("./logging.yaml"),
33+
"log_path": os.path.abspath("./"),
34+
"config_file": os.path.abspath("./config.yaml"),
35+
"playbooks_root_dir": os.path.abspath("./samples"),
3636
"debug": True
3737
}
3838
}

runner_service/services/playbook.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ansible_runner.exceptions import AnsibleRunnerException
1111
from runner_service import configuration
1212
from runner_service.cache import runner_cache, runner_stats
13-
from .utils import cleanup_dir, APIResponse
13+
from .utils import APIResponse
1414
from ..utils import fread
1515

1616
from ..cache import event_cache
@@ -193,15 +193,6 @@ def cb_event_handler(event_data):
193193
return True
194194

195195

196-
def commit_cmdline(options):
197-
cmd_file = os.path.join(configuration.settings.playbooks_root_dir,
198-
"env", "cmdline")
199-
runtime_overrides = ' '.join(options)
200-
logger.debug("Creating env/cmdline file: {}".format(runtime_overrides))
201-
with open(cmd_file, "w") as cmdline:
202-
cmdline.write(runtime_overrides)
203-
204-
205196
def start_playbook(playbook_name, vars=None, filter=None, tags=None):
206197
""" Initiate a playbook run """
207198

@@ -214,8 +205,15 @@ def start_playbook(playbook_name, vars=None, filter=None, tags=None):
214205

215206
# this should just be run_async, using 'run' hangs the root logger output
216207
# even when backgrounded
208+
209+
artifacts_dir = os.path.join(configuration.settings.playbooks_root_dir, "artifacts")
210+
private_data_dir = os.path.join(artifacts_dir, play_uuid)
211+
os.makedirs(private_data_dir)
217212
parms = {
218-
"private_data_dir": configuration.settings.playbooks_root_dir,
213+
"private_data_dir": private_data_dir,
214+
"project_dir": os.path.join(configuration.settings.playbooks_root_dir, 'project'),
215+
"inventory": os.path.join(configuration.settings.playbooks_root_dir, 'inventory'),
216+
"artifact_dir": artifacts_dir,
219217
"settings": settings,
220218
"finished_callback": cb_playbook_finished,
221219
"event_handler": cb_event_handler,
@@ -236,10 +234,6 @@ def start_playbook(playbook_name, vars=None, filter=None, tags=None):
236234
if limit_hosts:
237235
parms['limit'] = limit_hosts
238236

239-
logger.debug("Clearing up old env directory")
240-
cleanup_dir(os.path.join(configuration.settings.playbooks_root_dir,
241-
"env"))
242-
243237
cmdline = []
244238
if filter.get('check', 'false').lower() == 'true':
245239
cmdline.append('--check')
@@ -252,13 +246,11 @@ def start_playbook(playbook_name, vars=None, filter=None, tags=None):
252246
"{}".format(configuration.settings.target_user))
253247
cmdline.append("--user {}".format(configuration.settings.target_user))
254248

255-
if not configuration.settings.ssh_private_key.endswith('env/ssh_key'):
256-
logger.debug("Run the playbook with a private key override of "
257-
"{}".format(configuration.settings.ssh_private_key))
258-
cmdline.append("--private-key {}".format(configuration.settings.ssh_private_key))
249+
logger.debug("Run the playbook with a private key override of "
250+
"{}".format(configuration.settings.ssh_private_key))
251+
cmdline.append("--private-key {}".format(configuration.settings.ssh_private_key))
259252

260-
if cmdline:
261-
commit_cmdline(cmdline)
253+
parms['cmdline'] = ' '.join(cmdline)
262254

263255
_thread, _runner = run_async(**parms)
264256

runner_service/services/utils.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import yaml
44

55
import runner_service.configuration as configuration
6-
from runner_service.utils import rm_r
76

87

98
def playbook_exists(playbook_name):
@@ -19,12 +18,6 @@ def build_pb_path(play_uuid):
1918
play_uuid)
2019

2120

22-
def cleanup_dir(dir_name, exclude=['ssh_key', 'ssh_key.pub']):
23-
for _path_name in glob.glob("{}/*".format(dir_name)):
24-
if os.path.basename(_path_name) not in exclude:
25-
rm_r(_path_name)
26-
27-
2821
def writeYAML(data, path_name):
2922
try:
3023
with open(path_name, "w") as yaml_file:

0 commit comments

Comments
 (0)