def _run_playbook(playbook, config_path, extra_vars=None, display=True, load_config_vars=False): log = logger.getlogger() config_pointer_file = gen.get_python_path() + '/config_pointer_file' with open(config_pointer_file, 'w') as f: f.write(config_path) ansible_playbook = gen.get_ansible_playbook_path() inventory = ' -i ' + gen.get_python_path() + '/inventory.py' playbook = ' ' + playbook cmd = ansible_playbook + inventory + playbook if load_config_vars: cmd += f" --extra-vars '@{config_path}'" if extra_vars is not None: cmd += f" --extra-vars '{' '.join(extra_vars)}'" command = ['bash', '-c', cmd] log.debug('Run subprocess: %s' % ' '.join(command)) if display: process = Popen(command, cwd=gen.get_playbooks_path()) process.wait() stdout = '' else: process = Popen(command, stdout=PIPE, stderr=PIPE, cwd=gen.get_playbooks_path()) stdout, stderr = process.communicate() try: stdout = stdout.decode('utf-8') except AttributeError: pass return (process.returncode, stdout)
def _run_playbook(playbook, config_path): log = logger.getlogger() config_pointer_file = gen.get_python_path() + '/config_pointer_file' with open(config_pointer_file, 'w') as f: f.write(config_path) ansible_playbook = gen.get_ansible_playbook_path() inventory = ' -i ' + gen.get_python_path() + '/inventory.py' playbook = ' ' + playbook cmd = ansible_playbook + inventory + playbook command = ['bash', '-c', cmd] log.debug('Run subprocess: %s' % ' '.join(command)) process = subprocess.Popen(command, cwd=gen.get_playbooks_path()) process.wait()