Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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"
def get_hosts(cls, host, **kwargs):
inventory = kwargs.get('ansible_inventory')
return AnsibleRunner.get_runner(inventory).get_hosts(host or "all")
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']
def get_vars(host):
return AnsibleRunner(f.name).get_variables(host)
groups = {