How to use the testinfra.utils.ansible_runner 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 pieterlexis / ansible-json_file / tests / test_default.py View on Github external
import testinfra.utils.ansible_runner
import json

runner = testinfra.utils.ansible_runner.AnsibleRunner(
    '.molecule/ansible_inventory')

testinfra_hosts = runner.get_hosts('all')

def test_change_existing(Command):
    stdout = Command("cat /tmp/0.json").stdout
    data = json.loads(stdout)

    assert data['a'] == 'e'
    assert data['c'] == 'f'

def test_nested_change_existing(Command):
    stdout = Command("cat /tmp/1.json").stdout
    data = json.loads(stdout)

    assert data['c'] == {'d': 'f'}
github nginxinc / ansible-role-nginx / molecule / common / test_stable_push / test_default.py View on Github external
import nginx
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_nginx_is_installed(host):
    ngx = host.package("nginx")
    assert ngx.is_installed


def test_nginx_running_and_enabled(host):
    ngx = host.service("nginx")
    assert ngx.is_running
    assert ngx.is_enabled


def test_hosts_file(host):
    ngx = host.file('/etc/hosts')
github ansible / molecule / test / scenarios / verifier / molecule / testinfra / shared / test_shared.py View on Github external
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']
).get_hosts('all')


def test_ansible_hostname(host):
    f = host.file('/tmp/molecule/instance-1')

    assert not f.exists
github RebelCodeBase / testaid / test / unit / test_testaid_unit_boilerplate.py View on Github external
def test_testaid_unit_boilerplate_hosts_molecule_inventory_file(
        monkeypatch):
    monkeypatch.setenv('MOLECULE_INVENTORY_FILE', 'localhost')
    monkeypatch.setattr(testinfra.utils.ansible_runner.AnsibleRunner,
                        'get_hosts',
                        lambda x, y: ['testhost'])
    hosts = testaid.boilerplate.hosts()
    assert hosts == ['testhost']
github vmware / ansible-role-sshkeys / tests / test_default.py View on Github external
# Copyright 2015 VMware, Inc.  All rights reserved.
# SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-only

from __future__ import print_function
import testinfra.utils.ansible_runner


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

# Use testinfra to get a handy function to run commands locally
check_output = testinfra.get_backend(
    "local://"
).get_module("Command").check_output


def test_hosts_file(File):
    f = File('/root/.ssh/authorized_keys')
    assert f.exists
    assert f.user == 'root'
    assert f.group == 'root'

    command = check_output(
        'cat ~/.ssh/ansible_role_test_key.pub')
github hugoShaka / ansible-mailserver / test / suite / tools.py View on Github external
def database_address(request):
    import testinfra.utils.ansible_runner

    inventory = testinfra.utils.ansible_runner.AnsibleRunner(
        os.environ["MOLECULE_INVENTORY_FILE"]
    )

    database_hosts = inventory.get_hosts("db")
    if len(database_hosts) != 1:
        raise ValueError("Multiple databases are not correctly suported")
    database_facts = inventory.run_module(database_hosts[0], "setup", [])
    database_ip = database_facts["ansible_facts"]["ansible_default_ipv4"]["address"]

    return database_ip
github ansible / molecule / molecule / cookiecutter / scenario / verifier / testinfra / {{cookiecutter.molecule_directory}} / {{cookiecutter.scenario_name}} / {{cookiecutter.verifier_directory}} / test_default.py View on Github external
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']
).get_hosts('all')


def test_hosts_file(host):
    f = host.file('/etc/hosts')

    assert f.exists
    assert f.user == 'root'
    assert f.group == 'root'
github teralytics / ansible-hdfs / tests / test_default.py View on Github external
import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    '.molecule/inventory').get_hosts('all')


def get(e, nodeName):
    arg = r"./property[name='{nodename}']".format(nodename=nodeName)
    return e.find(arg)[1].text


def test_hosts_file(File):
    f = File('/etc/hosts')

    assert f.exists
    assert f.user == 'root'
    assert f.group == 'root'
github remyma / ansible-springboot / tests / test_install.py View on Github external
import testinfra.utils.ansible_runner

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


def test_application_running(Service):
    application = Service("spring-boot-sample")
    assert application.is_enabled


def test_application_properties_exists(File):
    propertyFile = File("/opt/spring-boot-sample/application.yml")
    assert propertyFile.exists


def test_application_conf_exists(File):
    configFile = File("/opt/spring-boot-sample/spring-boot-sample.conf")
    assert configFile.exists
github nginxinc / ansible-role-nginx / molecule / common / test_module / test_default.py View on Github external
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_nginx_is_installed(host):
    ngx = host.package("nginx")
    assert ngx.is_installed


def test_nginx_running_and_enabled(host):
    ngx = host.service("nginx")
    assert ngx.is_running
    assert ngx.is_enabled


def test_hosts_file(host):
    ngx = host.file('/etc/hosts')