def run_playbook(playbook, inventory, *args, **kwargs):
env = ansible_env(os.environ.copy())
cmd = ['ansible-playbook', '-i', inventory, playbook] + list(args)
if verbosity():
cmd += ['-' + ('v' * verbosity())]
show_timestamp = False
if 'timestamp' in kwargs:
show_timestamp = kwargs['timestamp']
del kwargs['timestamp']
output = print
if show_timestamp:
output = timestamp
logger.info('running %s', ' '.join(cmd))
logger.debug('env: %r', env)
process = Popen(cmd, env=env, stdout=PIPE,
bufsize=1, **kwargs)
for line in iter(process.stdout.readline, b''):
output(line[:-1])
# empty output buffers
process.poll()
return process.returncode
评论列表
文章目录