Beispiel #1
0
def _copy_resources_to_hosts(_hosts):
    ssh = SshHandler.get()
    try:
        ssh.test_hosts(_hosts)
    except Exception as e:
        raise e

    resources_dir = os.path.dirname(os.path.realpath(__file__))
    modules_dir = "{0}/modules".format(resources_dir)
    common_dir = "{0}/common".format(resources_dir)
    conf_file = "{0}/defaults.conf".format(__recipes_directory)

    if util.has_localhost(_hosts):
        _copy_resources_local()
        util.remove_localhost(_hosts)

    generate_conf_file(conf_file)

    """ Copy modules and conf to hosts """
    for host in _hosts:
        try:
            ssh.transfer_file(modules_dir, __recipes_directory, host)
            ssh.transfer_file(common_dir, __recipes_directory, host)
            ssh.transfer_file(conf_file, __recipes_directory, host)
        except Exception as e:
            raise e
Beispiel #2
0
def _run_recipe_in_hosts(recipe_file, recipes_dir, _hosts):
    hosts = set(_hosts)
    ssh = SshHandler.get()

    if util.has_localhost(hosts):
        _run_recipe_local(recipe_file)
        util.remove_localhost(hosts)

    for host in hosts:
        try:
            ssh.transfer_file(recipe_file, recipes_dir, host)
            ssh.run_recipe(recipe_file, host)
        except Exception as e:
            raise e