How to use the pyinfra.logger.info function in pyinfra

To help you get started, we’ve selected a few pyinfra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Fizzadar / pyinfra / pyinfra / cli / util.py View on Github external
def load_deploy_file(state, filename):
    for host in state.inventory:
        pseudo_host.set(host)

        exec_file(filename)

        state.ready_host(host)

        logger.info('{0} {1} {2}'.format(
            '[{}]'.format(click.style(host.name, bold=True)),
            click.style('Ready:', 'green'),
            click.style(filename, bold=True),
        ))

    # Remove any pseudo host
    pseudo_host.reset()

    # Un-ready the hosts - this is so that any hooks or callbacks during the deploy
    # can still use facts as expected.
    state.ready_hosts = set()
github Fizzadar / pyinfra / pyinfra / api / connectors / ssh.py View on Github external
session = client.get_transport().open_session()
        AgentRequestHandler(session)

        # Log
        log_message = '{0}{1}'.format(
            host.print_prefix,
            click.style('Connected', 'green'),
        )

        if for_fact:
            log_message = '{0}{1}'.format(
                log_message,
                ' (for {0} fact)'.format(for_fact),
            )

        logger.info(log_message)

        return client

    except AuthenticationException:
        auth_kwargs = {}

        for key, value in kwargs.items():
            if key in ('username', 'password'):
                auth_kwargs[key] = value
                continue

            if key == 'pkey' and value:
                auth_kwargs['key'] = host.data.ssh_key

        auth_args = ', '.join(
            '{0}={1}'.format(key, value)
github Fizzadar / pyinfra / pyinfra / api / connectors / local.py View on Github external
def connect(state, host, for_fact=None):
    # Log
    log_message = '{0}{1}'.format(
        host.print_prefix,
        click.style('Connected', 'green'),
    )

    if for_fact:
        log_message = '{0}{1}'.format(
            log_message,
            ' (for {0} fact)'.format(for_fact),
        )

    logger.info(log_message)

    return True
github Fizzadar / pyinfra / pyinfra / __main__.py View on Github external
def loop_hosts():
            # This actually does the op build
            for host in inventory:
                pseudo_host.set(host)
                exec_file(arguments['deploy'])
                state.ready_host(host)

                logger.info('{0} {1}'.format(
                    '[{}]'.format(colored(host.name, attrs=['bold'])),
                    colored('Ready', 'green')
                ))
github Fizzadar / pyinfra / pyinfra_cli / prints.py View on Github external
]

        if not hosts:
            continue

        if groups:
            rows.append((logger.info, 'Groups: {0}'.format(
                click.style(' / '.join(groups), bold=True),
            )))
        else:
            rows.append((logger.info, 'Ungrouped:'))

        for host in hosts:
            # Didn't conenct to this host?
            if host not in state.activated_hosts:
                rows.append((logger.info, [
                    host.style_print_prefix('red', bold=True),
                    click.style('No connection', 'red'),
                ]))
                continue

            results = state.results[host]

            meta = state.meta[host]
            success_ops = results['success_ops']
            error_ops = results['error_ops']

            host_args = ('green',)
            host_kwargs = {}

            # If all ops got complete
            if results['ops'] == meta['ops']:
github Fizzadar / pyinfra / pyinfra / cli.py View on Github external
else:
            meta = state.meta[hostname]
            success_ops = results['success_ops']
            error_ops = results['error_ops']

            # If all ops got complete (even with ignored_errors)
            if results['ops'] == meta['ops']:
                # Yellow if ignored any errors, else green
                color = 'green' if error_ops == 0 else 'yellow'
                host_string = colored(hostname, color)

            # Ops did not complete!
            else:
                host_string = colored(hostname, 'red', attrs=['bold'])

            logger.info('[{0}]\tSuccessful: {1}\t    Errors: {2}\t    Commands: {3}/{4}'.format(
                host_string,
                colored(success_ops, attrs=['bold']),
                error_ops
                if error_ops == 0
                else colored(error_ops, 'red', attrs=['bold']),
                results['commands'], meta['commands']
            ))
github Fizzadar / pyinfra / pyinfra / api / facts.py View on Github external
if status and stdout:
                data = fact.process(stdout)

            hostname_facts[host] = data

        log_name = click.style(name, bold=True)

        filtered_args = list(filter(None, args))
        if filtered_args:
            log = 'Loaded fact {0}: {1}'.format(log_name, tuple(filtered_args))
        else:
            log = 'Loaded fact {0}'.format(log_name)

        if state.print_fact_info:
            logger.info(log)
        else:
            logger.debug(log)

        # Check we've not failed
        if not ignore_errors:
            state.fail_hosts(failed_hosts)

        # Assign the facts
        state.facts.setdefault(fact_hash, {}).update(hostname_facts)

    return state.facts[fact_hash]
github Fizzadar / pyinfra / pyinfra / api / connectors / ssh.py View on Github external
session = client.get_transport().open_session()
        AgentRequestHandler(session)

        # Log
        log_message = '{0}{1}'.format(
            host.print_prefix,
            click.style('Connected', 'green'),
        )

        if for_fact:
            log_message = '{0}{1}'.format(
                log_message,
                ' (for {0} fact)'.format(for_fact),
            )

        logger.info(log_message)

        return client

    except AuthenticationException as e:
        auth_kwargs = {}

        for key, value in kwargs.items():
            if key in ('username', 'password'):
                auth_kwargs[key] = value
                continue

            if key == 'pkey' and value:
                auth_kwargs['key'] = host.data.ssh_key

        auth_args = ', '.join(
            '{0}={1}'.format(key, value)
github Fizzadar / pyinfra / pyinfra / api / operations.py View on Github external
else:
            raise TypeError('{0} is an invalid pyinfra command!'.format(command))

        # Break the loop to trigger a failure
        if status is False:
            break
        else:
            state.results[host]['commands'] += 1

    # Commands didn't break, so count our successes & return True!
    else:
        # Count success
        state.results[host]['ops'] += 1
        state.results[host]['success_ops'] += 1

        logger.info('{0}{1}'.format(
            host.print_prefix,
            click.style(
                'Success' if len(op_data['commands']) > 0 else 'No changes',
                'green',
            ),
        ))

        # Trigger any success handler
        if op_meta['on_success']:
            op_meta['on_success'](state, host, op_hash)

        return True

    # Up error_ops & log
    state.results[host]['error_ops'] += 1