Пример #1
0
def execute_file_copy_scripts(environment, target_hosts, check_mode=True):
    file_root = os.path.join('/tmp', REMOTE_MIGRATION_ROOT)
    command = "{}{}".format(
        os.path.join(file_root, FILE_MIGRATION_RSYNC_SCRIPT),
        ' --dry-run' if check_mode else ''
    )
    piv_command = PrivilegedCommand('ansible', environment.get_ansible_user_password(), command)
    results = piv_command.run_command(target_hosts, parallel_pool_size=len(target_hosts))
    non_zero_returns = [ret.return_code for ret in results.values() if ret.return_code]
    return non_zero_returns[0] if non_zero_returns else 0
Пример #2
0
def execute_file_copy_scripts(environment, target_hosts, check_mode=True):
    file_root = os.path.join('/tmp', REMOTE_MIGRATION_ROOT)
    command = "{}{}".format(
        os.path.join(file_root, FILE_MIGRATION_RSYNC_SCRIPT),
        ' --dry-run' if check_mode else ''
    )
    piv_command = PrivilegedCommand('ansible', environment.get_ansible_user_password(), command)
    results = piv_command.run_command(target_hosts, parallel_pool_size=len(target_hosts))
    non_zero_returns = [ret.return_code for ret in results.values() if ret.return_code]
    return non_zero_returns[0] if non_zero_returns else 0
Пример #3
0
    def get_present_dbs( args):
        dbs_present_in_host = collections.defaultdict(list)
        args.server = 'postgresql'
        ansible_username = '******'
        command = "python /usr/local/sbin/db-tools.py  --list-all"

        environment = get_environment(args.env_name)
        ansible_password = environment.get_ansible_user_password()
        host_addresses = get_instance_group(args.env_name, args.server)
        user_as = 'postgres'

        privileged_command = PrivilegedCommand(ansible_username, ansible_password, command, user_as)

        present_db_op = privileged_command.run_command(host_addresses)

        # List from Postgresql query.

        for host_address in present_db_op.keys():
            dbs_present_in_host[host_address] = present_db_op[host_address].split("\r\n")

        return dbs_present_in_host
Пример #4
0
    def get_present_dbs( args):
        dbs_present_in_host = collections.defaultdict(list)
        args.server = 'postgresql'
        ansible_username = '******'
        command = "python /usr/local/sbin/db-tools.py  --list-all"

        environment = get_environment(args.env_name)
        ansible_password = environment.get_ansible_user_password()
        host_addresses = get_instance_group(args.env_name, args.server)
        user_as = 'postgres'

        privileged_command = PrivilegedCommand(ansible_username, ansible_password, command, user_as)

        present_db_op = privileged_command.run_command(host_addresses)

        # List from Postgresql query.

        for host_address in present_db_op.keys():
            dbs_present_in_host[host_address] = present_db_op[host_address].split("\r\n")

        return dbs_present_in_host
Пример #5
0
def _genearate_and_fetch_key(env, host, user, ansible_context, working_directory):
    user_args = "name={} generate_ssh_key=yes".format(user)
    run_ansible_module(env, ansible_context, host, 'user', user_args, True, None, None)

    user_home_output = PrivilegedCommand(
        'ansible',
        env.get_ansible_user_password(),
        "getent passwd {} | cut -d: -f6".format(user)
    ).run_command(host)
    user_home = user_home_output[host]

    fetch_args = "src={user_home}/.ssh/id_rsa.pub dest={key_tmp} flat=yes fail_on_missing=yes".format(
        user_home=user_home, key_tmp=os.path.join(working_directory, 'id_rsa.tmp')
    )
    run_ansible_module(env, ansible_context, host, 'fetch', fetch_args, True, None, None)