Beispiel #1
0
def cli(inventory, limit, command):
    """
    Run shell command on multiple remote servers.
    """
    summary(inventory)

    try:
        command = ' '.join(map(quote, command))
        click.echo('Running %s' % command)
        run(inventory, command, limit)
    except IOError as e:
        click.secho('error: %s' % e.message, err=True, fg='red')
Beispiel #2
0
def cli(timeout, inventory, host, extra):
    """
    Connect to a remote server.
    """
    summary(inventory)

    try:
        host = ACHost(inventory, host)
    except NameError as e:
        fatal(e.message)
    except IOError as e:
        fatal(e.message)
    except AnsibleYAMLValidationFailed as e:
        fatal(e.message)

    ip = host.ssh_host()

    services = _services(ip, timeout)
    args = []

    if services:
        click.secho('\nThe following SSH forwarding have automatically '
                    'been made:\n', fg='green', bold=True)

        for service in services:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.bind(('localhost', 0))
            _, local_port = s.getsockname()
            s.close()

            args += ['-L', '%s:%s:%s' % (
                local_port,
                ip,
                service['port'])
            ]

            click.echo('%s @ ' % click.style(service['name'], fg='cyan'),
                       nl=False)

            if 'path' in service:
                click.secho('http://localhost:%s%s' % (
                    local_port,
                    service['path']
                ), fg='magenta')
            else:
                click.secho('localhost:%s' % local_port, fg='magenta')

        click.echo()

    if extra:
        args += ['--'] + list(extra)

    _ssh(ip, timeout, *args)
Beispiel #3
0
def cli(env, inventory, extra):
    """
    Provision remote servers.
    """
    summary(inventory)

    (organization, env) = env.split('/', 1)

    try:
        run_env(organization, env, inventory, *extra, timestamp=True)
    except IOError as e:
        click.secho('error: %s' % e.message, err=True, fg='red')
Beispiel #4
0
def cli(inventory, src, dest, extra):
    """
    Sync files between your local machine and remote servers.
    """
    summary(inventory)

    src = _update_rsync_uri(inventory, src)
    dest = _update_rsync_uri(inventory, dest)

    cmd = ['rsync', '-av'] + list(extra) +\
          [src, dest]

    logger.info('Running %s' % ' '.join(map(quote, cmd)))

    call(cmd)
Beispiel #5
0
def cli(job, inventory, extra):
    """
    Run maintenance jobs on remote servers.
    """
    if not job:
        for job in list_jobs():
            (job_name, job_desc) = job
            if not job_desc:
                click.echo('* %s' % (
                    click.style(job_name, bold=True),
                ))
            else:
                click.echo('* %-35s - %s' % (
                    click.style(job_name, bold=True),
                    job_desc
                ))
        return

    if not inventory:
        (job_desc, job_help) = get_job_help(job)

        click.echo(click.style(job, bold=True))
        if job_desc:
            click.echo("%s" % job_desc)
        if job_help:
            click.echo("\n%s" % job_help.strip())
        return

    summary(inventory)

    try:
        sys.exit(run_job(job, inventory, *extra, timestamp=True))
    except IOError as e:
        click.secho('error: %s' % e.message, err=True, fg='red')
        sys.exit(1)
    except NameError as e:
        click.secho('error: %s' % e.message, err=True, fg='red')
        sys.exit(1)
Beispiel #6
0
def cli(timeout, inventory, host, extra):
    """
    Connect to a remote server.
    """
    summary(inventory)

    user = None
    if '@' in host:
        (user, host) = host.split('@', 1)

    try:
        host = ACHost(inventory, host)
    except NameError as e:
        fatal(e.message)
    except IOError as e:
        fatal(e.message)
    except AnsibleError as e:
        fatal(e.message)

    ip = host.ssh_host()
    args = []

    hostvars = host.variables()
    if 'ansible_ssh_common_args' in hostvars:
        args += shlex.split(hostvars['ansible_ssh_common_args'])

    if user:
        args += ['-o', 'User %s' % user]

    services = _services(ip, timeout, *args)

    if services:
        args += _services_args(services, ip)

    if extra:
        args += ['--'] + list(extra)

    _ssh(ip, timeout, *args)
Beispiel #7
0
def cli(inventory, src, dest, extra):
    """
    Sync files between your local machine and remote servers.
    """
    summary(inventory)

    src, src_hostvars = _update_rsync_uri(inventory, src)
    dest, dest_hostvars = _update_rsync_uri(inventory, dest)

    ssh_args = None
    if src_hostvars and 'ansible_ssh_common_args' in src_hostvars:
        ssh_args = src_hostvars['ansible_ssh_common_args']
    if dest_hostvars and 'ansible_ssh_common_args' in dest_hostvars:
        ssh_args = dest_hostvars['ansible_ssh_common_args']

    cmd = ['rsync', '-av']
    if ssh_args:
        cmd += ['-e', 'ssh %s' % ssh_args]
    cmd += list(extra) + [src, dest]

    logger.info('Running %s' % ' '.join(map(quote, cmd)))

    call(cmd)