How to use the testinfra.utils.ansible_runner.AnsibleRunner function in testinfra

To help you get started, we’ve selected a few testinfra 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 dj-wasabi / ansible-zabbix-agent / tests / test_docker.py View on Github external
from testinfra.utils.ansible_runner import AnsibleRunner

testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')


def test_zabbixagent_running_and_enabled(Service, SystemInfo):
    zabbixagent = Service("zabbix-agent")
    # Find out why this is not working for linuxmint and opensus
    if SystemInfo.distribution not in ['linuxmint', 'opensuse']:
        assert zabbixagent.is_running
        assert zabbixagent.is_enabled


def test_zabbix_agent_dot_conf(File, SystemInfo):
    if SystemInfo.distribution in ['opensuse']:
        passwd = File("/etc/zabbix/zabbix-agentd.conf")
    else:
        passwd = File("/etc/zabbix/zabbix_agentd.conf")
    assert passwd.user == "root"
github philpep / testinfra / testinfra / backend / ansible.py View on Github external
def get_hosts(cls, host, **kwargs):
        inventory = kwargs.get('ansible_inventory')
        return AnsibleRunner.get_runner(inventory).get_hosts(host or "all")
github philpep / testinfra / test / test_backends.py View on Github external
def test_ansible_config():
    # test testinfra use ANSIBLE_CONFIG
    tmp = tempfile.NamedTemporaryFile
    with tmp(suffix='.cfg') as cfg, tmp() as inventory:
        cfg.write((
            b'[defaults]\n'
            b'inventory=' + inventory.name.encode() + b'\n'
        ))
        cfg.flush()
        inventory.write(b'h\n')
        inventory.flush()
        old = os.environ.get('ANSIBLE_CONFIG')
        os.environ['ANSIBLE_CONFIG'] = cfg.name
        try:
            assert AnsibleRunner(None).get_hosts('all') == ['h']
        finally:
            if old is not None:
                os.environ['ANSIBLE_CONFIG'] = old
            else:
                del os.environ['ANSIBLE_CONFIG']
github philpep / testinfra / test / test_backends.py View on Github external
def get_vars(host):
            return AnsibleRunner(f.name).get_variables(host)
        groups = {