예제 #1
0
def deploy_ansible_playbook(prefix,
                            playbook_path,
                            vars_dict=None,
                            env_vars=None,
                            host_key_checking=False,
                            user='******',
                            **kwargs):

    if not env_vars:
        env_vars = {}

    if not host_key_checking:
        env_vars.update({'ANSIBLE_HOST_KEY_CHECKING': 'False'})

    ansible_instance = lago_ansible.LagoAnsible(prefix)

    if vars_dict:
        extra_vars = ' '.join(
            ['{}={}'.format(k, v) for k, v in vars_dict.viewitems()])
    else:
        extra_vars = ''

    extra_args = list(itertools.chain(*kwargs.viewitems()))

    with ansible_instance.get_inventory_temp_file() as inventory:
        cmd = [
            'ansible-playbook',
            playbook_path,
            '-i',
            inventory.name,
            '-u',
            user,
            '-v',
            '-e',
            extra_vars,
        ]
        cmd.extend(extra_args)

        return utils.run_interactive_command(cmd, env=env_vars)
예제 #2
0
def do_generate_ansible_hosts(prefix, keys, **kwargs):
    print(lago_ansible.LagoAnsible(prefix).get_inventory_str(keys))
예제 #3
0
 def lago_ansible_instance(self):
     return lago_ansible.LagoAnsible(generate_prefix())