diff --git a/.config/molecule/config.yml b/.config/molecule/config.yml index db338a1c..5bb016d9 100644 --- a/.config/molecule/config.yml +++ b/.config/molecule/config.yml @@ -61,6 +61,8 @@ platforms: command: /lib/systemd/systemd verifier: name: testinfra + additional_files_or_dirs: + - "../../../../../.testinfra/testinfra_helpers.py" provisioner: playbooks: converge: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/converge.yml" diff --git a/.testinfra/testinfra_helpers.py b/.testinfra/testinfra_helpers.py new file mode 100644 index 00000000..962f465e --- /dev/null +++ b/.testinfra/testinfra_helpers.py @@ -0,0 +1,67 @@ +import os +import testinfra + + +def get_ansible_version(): + """ + Get the current Ansible version from localhost using the 'debug' module. + + Returns: + str: The current Ansible version (major.minor). + """ + localhost = testinfra.get_host( + "ansible://localhost?ansible_inventory=localhost," + ) + local_ansible_version = localhost.ansible("debug", "var=ansible_version") + ansible_version = '.'.join( + local_ansible_version['ansible_version']['full'].split('.')[:2] + ) + return ansible_version + + +def filter_compatible_hosts(inventory, ansible_version): + """ + Filter hosts based on Ansible version compatibility. + + Args: + inventory (str): The inventory file path. + ansible_version (str): The current Ansible version (major.minor). + + Returns: + list: A list of compatible hosts that do not have the current Ansible + version in their exclude_ansible_vers hostvars. + """ + ansible_runner = testinfra.utils.ansible_runner.AnsibleRunner(inventory) + all_hosts = ansible_runner.get_hosts('all') + compatible_hosts = [] + + for host in all_hosts: + # Get host variables + host_vars = ansible_runner.get_variables(host) + + # Check if the host should be excluded + if 'exclude_ansible_vers' in host_vars: + excluded_versions = host_vars['exclude_ansible_vers'] + if ansible_version in excluded_versions: + continue + compatible_hosts.append(host) + + return compatible_hosts + + +def get_target_hosts(): + """ + Get the filtered target hosts based on the current Ansible version. + + Returns: + list: A list of hosts that are compatible with + the current Ansible version. + """ + # Get current Ansible version + current_ansible_version = get_ansible_version() + + # Get the inventory file from environment + inventory_file = os.environ['MOLECULE_INVENTORY_FILE'] + + # Filter the hosts based on the exclusion criteria + return filter_compatible_hosts(inventory_file, current_ansible_version) diff --git a/roles/alertmanager/molecule/alternative/tests/test_alternative.py b/roles/alertmanager/molecule/alternative/tests/test_alternative.py index 8326c05f..bfc3eba1 100644 --- a/roles/alertmanager/molecule/alternative/tests/test_alternative.py +++ b/roles/alertmanager/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("dirs", [ diff --git a/roles/alertmanager/molecule/default/tests/test_default.py b/roles/alertmanager/molecule/default/tests/test_default.py index 15a360e5..1f2599c2 100644 --- a/roles/alertmanager/molecule/default/tests/test_default.py +++ b/roles/alertmanager/molecule/default/tests/test_default.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner import pytest +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("dirs", [ diff --git a/roles/alertmanager/molecule/latest/tests/test_latest.py b/roles/alertmanager/molecule/latest/tests/test_latest.py index bd4aa1b2..c328ed75 100644 --- a/roles/alertmanager/molecule/latest/tests/test_latest.py +++ b/roles/alertmanager/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/bind_exporter/molecule/alternative/tests/test_alternative.py b/roles/bind_exporter/molecule/alternative/tests/test_alternative.py index 18ea53de..47703c40 100644 --- a/roles/bind_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/bind_exporter/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_service(host): diff --git a/roles/bind_exporter/molecule/default/tests/test_default.py b/roles/bind_exporter/molecule/default/tests/test_default.py index 64e8251e..18b149e7 100644 --- a/roles/bind_exporter/molecule/default/tests/test_default.py +++ b/roles/bind_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/bind_exporter/molecule/latest/tests/test_latest.py b/roles/bind_exporter/molecule/latest/tests/test_latest.py index dc9e0403..1ba88f86 100644 --- a/roles/bind_exporter/molecule/latest/tests/test_latest.py +++ b/roles/bind_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/blackbox_exporter/molecule/alternative/tests/test_alternative.py b/roles/blackbox_exporter/molecule/alternative/tests/test_alternative.py index 5d4fb2ed..680b2f16 100644 --- a/roles/blackbox_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/blackbox_exporter/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/blackbox_exporter/molecule/default/tests/test_default.py b/roles/blackbox_exporter/molecule/default/tests/test_default.py index b54460a9..7787cac6 100644 --- a/roles/blackbox_exporter/molecule/default/tests/test_default.py +++ b/roles/blackbox_exporter/molecule/default/tests/test_default.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/blackbox_exporter/molecule/latest/tests/test_latest.py b/roles/blackbox_exporter/molecule/latest/tests/test_latest.py index 8b5955ea..65f093e9 100644 --- a/roles/blackbox_exporter/molecule/latest/tests/test_latest.py +++ b/roles/blackbox_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/cadvisor/molecule/alternative/tests/test_alternative.py b/roles/cadvisor/molecule/alternative/tests/test_alternative.py index 39272e9b..fdd11758 100644 --- a/roles/cadvisor/molecule/alternative/tests/test_alternative.py +++ b/roles/cadvisor/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_service(host): diff --git a/roles/cadvisor/molecule/default/tests/test_default.py b/roles/cadvisor/molecule/default/tests/test_default.py index 3d58b223..c4f240f4 100644 --- a/roles/cadvisor/molecule/default/tests/test_default.py +++ b/roles/cadvisor/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_files(host): diff --git a/roles/cadvisor/molecule/latest/tests/test_alternative.py b/roles/cadvisor/molecule/latest/tests/test_alternative.py index 966c1141..11fb025e 100644 --- a/roles/cadvisor/molecule/latest/tests/test_alternative.py +++ b/roles/cadvisor/molecule/latest/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/chrony_exporter/molecule/alternative/tests/test_alternative.py b/roles/chrony_exporter/molecule/alternative/tests/test_alternative.py index b8714e1d..34b5c169 100644 --- a/roles/chrony_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/chrony_exporter/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/chrony_exporter/molecule/default/tests/test_default.py b/roles/chrony_exporter/molecule/default/tests/test_default.py index bceddff0..f3d272a1 100644 --- a/roles/chrony_exporter/molecule/default/tests/test_default.py +++ b/roles/chrony_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/chrony_exporter/molecule/latest/tests/test_alternative.py b/roles/chrony_exporter/molecule/latest/tests/test_alternative.py index a3131111..ee22dc06 100644 --- a/roles/chrony_exporter/molecule/latest/tests/test_alternative.py +++ b/roles/chrony_exporter/molecule/latest/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/fail2ban_exporter/molecule/alternative/tests/test_alternative.py b/roles/fail2ban_exporter/molecule/alternative/tests/test_alternative.py index 35b1f412..d13dfa00 100644 --- a/roles/fail2ban_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/fail2ban_exporter/molecule/alternative/tests/test_alternative.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_service(host): diff --git a/roles/fail2ban_exporter/molecule/default/tests/test_default.py b/roles/fail2ban_exporter/molecule/default/tests/test_default.py index d5448e53..2871795b 100644 --- a/roles/fail2ban_exporter/molecule/default/tests/test_default.py +++ b/roles/fail2ban_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_files(host): diff --git a/roles/fail2ban_exporter/molecule/latest/tests/test_latest.py b/roles/fail2ban_exporter/molecule/latest/tests/test_latest.py index 4ce298bf..3f88af7d 100644 --- a/roles/fail2ban_exporter/molecule/latest/tests/test_latest.py +++ b/roles/fail2ban_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/ipmi_exporter/molecule/alternative/tests/test_alternative.py b/roles/ipmi_exporter/molecule/alternative/tests/test_alternative.py index e673e56d..86b89012 100644 --- a/roles/ipmi_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/ipmi_exporter/molecule/alternative/tests/test_alternative.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/ipmi_exporter/molecule/default/tests/test_default.py b/roles/ipmi_exporter/molecule/default/tests/test_default.py index fcd30e46..bcde0128 100644 --- a/roles/ipmi_exporter/molecule/default/tests/test_default.py +++ b/roles/ipmi_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/ipmi_exporter/molecule/latest/tests/test_latest.py b/roles/ipmi_exporter/molecule/latest/tests/test_latest.py index 0cfac425..3636bd34 100644 --- a/roles/ipmi_exporter/molecule/latest/tests/test_latest.py +++ b/roles/ipmi_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/memcached_exporter/molecule/alternative/tests/test_alternative.py b/roles/memcached_exporter/molecule/alternative/tests/test_alternative.py index 288fbf8f..2f123708 100644 --- a/roles/memcached_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/memcached_exporter/molecule/alternative/tests/test_alternative.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/memcached_exporter/molecule/default/tests/test_default.py b/roles/memcached_exporter/molecule/default/tests/test_default.py index 3e70a8b4..eeccbee9 100644 --- a/roles/memcached_exporter/molecule/default/tests/test_default.py +++ b/roles/memcached_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/memcached_exporter/molecule/latest/tests/test_latest.py b/roles/memcached_exporter/molecule/latest/tests/test_latest.py index 700ad0f1..ecd2e09f 100644 --- a/roles/memcached_exporter/molecule/latest/tests/test_latest.py +++ b/roles/memcached_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/mongodb_exporter/molecule/alternative/tests/test_alternative.py b/roles/mongodb_exporter/molecule/alternative/tests/test_alternative.py index a102ea94..66e00949 100644 --- a/roles/mongodb_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/mongodb_exporter/molecule/alternative/tests/test_alternative.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/mongodb_exporter/molecule/default/tests/test_default.py b/roles/mongodb_exporter/molecule/default/tests/test_default.py index 53e3858d..c8cf3caa 100644 --- a/roles/mongodb_exporter/molecule/default/tests/test_default.py +++ b/roles/mongodb_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/mongodb_exporter/molecule/latest/tests/test_latest.py b/roles/mongodb_exporter/molecule/latest/tests/test_latest.py index 7f6a621c..07528b62 100644 --- a/roles/mongodb_exporter/molecule/latest/tests/test_latest.py +++ b/roles/mongodb_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/mysqld_exporter/molecule/alternative/tests/test_alternative.py b/roles/mysqld_exporter/molecule/alternative/tests/test_alternative.py index 734b97fb..92a34c78 100644 --- a/roles/mysqld_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/mysqld_exporter/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_service(host): diff --git a/roles/mysqld_exporter/molecule/default/tests/test_default.py b/roles/mysqld_exporter/molecule/default/tests/test_default.py index 930779fb..1bd8ac8a 100644 --- a/roles/mysqld_exporter/molecule/default/tests/test_default.py +++ b/roles/mysqld_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/mysqld_exporter/molecule/latest/tests/test_latest.py b/roles/mysqld_exporter/molecule/latest/tests/test_latest.py index 56cec8c9..c5c21688 100644 --- a/roles/mysqld_exporter/molecule/latest/tests/test_latest.py +++ b/roles/mysqld_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/nginx_exporter/molecule/alternative/tests/test_alternative.py b/roles/nginx_exporter/molecule/alternative/tests/test_alternative.py index 9f1e8e7d..8521755b 100644 --- a/roles/nginx_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/nginx_exporter/molecule/alternative/tests/test_alternative.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/nginx_exporter/molecule/default/tests/test_default.py b/roles/nginx_exporter/molecule/default/tests/test_default.py index 18339fae..d7c4a9fd 100644 --- a/roles/nginx_exporter/molecule/default/tests/test_default.py +++ b/roles/nginx_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/nginx_exporter/molecule/latest/tests/test_latest.py b/roles/nginx_exporter/molecule/latest/tests/test_latest.py index 6dffb2c4..8a4545af 100644 --- a/roles/nginx_exporter/molecule/latest/tests/test_latest.py +++ b/roles/nginx_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/node_exporter/molecule/alternative/tests/test_alternative.py b/roles/node_exporter/molecule/alternative/tests/test_alternative.py index 0d5b517b..4d9f7108 100644 --- a/roles/node_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/node_exporter/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/node_exporter/molecule/default/tests/test_default.py b/roles/node_exporter/molecule/default/tests/test_default.py index 8ac237da..24688320 100644 --- a/roles/node_exporter/molecule/default/tests/test_default.py +++ b/roles/node_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/node_exporter/molecule/latest/tests/test_latest.py b/roles/node_exporter/molecule/latest/tests/test_latest.py index 81228020..41fbc501 100644 --- a/roles/node_exporter/molecule/latest/tests/test_latest.py +++ b/roles/node_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/postgres_exporter/molecule/alternative/tests/test_alternative.py b/roles/postgres_exporter/molecule/alternative/tests/test_alternative.py index 113fd33c..1d39feee 100644 --- a/roles/postgres_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/postgres_exporter/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_service(host): diff --git a/roles/postgres_exporter/molecule/default/tests/test_default.py b/roles/postgres_exporter/molecule/default/tests/test_default.py index d497d5b1..d2eb60d7 100644 --- a/roles/postgres_exporter/molecule/default/tests/test_default.py +++ b/roles/postgres_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/postgres_exporter/molecule/latest/tests/test_latest.py b/roles/postgres_exporter/molecule/latest/tests/test_latest.py index 2d8c9d49..5612095f 100644 --- a/roles/postgres_exporter/molecule/latest/tests/test_latest.py +++ b/roles/postgres_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/process_exporter/molecule/alternative/tests/test_alternative.py b/roles/process_exporter/molecule/alternative/tests/test_alternative.py index 4922514b..18ac0f16 100644 --- a/roles/process_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/process_exporter/molecule/alternative/tests/test_alternative.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/process_exporter/molecule/default/tests/test_default.py b/roles/process_exporter/molecule/default/tests/test_default.py index 71ea4d36..066e268f 100644 --- a/roles/process_exporter/molecule/default/tests/test_default.py +++ b/roles/process_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/process_exporter/molecule/latest/tests/test_latest.py b/roles/process_exporter/molecule/latest/tests/test_latest.py index 63e5d156..0c7b0a68 100644 --- a/roles/process_exporter/molecule/latest/tests/test_latest.py +++ b/roles/process_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/prometheus/molecule/agentmode/tests/test_agentmode.py b/roles/prometheus/molecule/agentmode/tests/test_agentmode.py index 4789e6dc..288aed60 100644 --- a/roles/prometheus/molecule/agentmode/tests/test_agentmode.py +++ b/roles/prometheus/molecule/agentmode/tests/test_agentmode.py @@ -1,13 +1,11 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os import yaml -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.fixture() diff --git a/roles/prometheus/molecule/alternative/tests/test_alternative.py b/roles/prometheus/molecule/alternative/tests/test_alternative.py index 8635a866..94c9e1c1 100644 --- a/roles/prometheus/molecule/alternative/tests/test_alternative.py +++ b/roles/prometheus/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("dirs", [ diff --git a/roles/prometheus/molecule/default/tests/test_default.py b/roles/prometheus/molecule/default/tests/test_default.py index da6305b6..518bcfd8 100644 --- a/roles/prometheus/molecule/default/tests/test_default.py +++ b/roles/prometheus/molecule/default/tests/test_default.py @@ -1,13 +1,11 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os import yaml -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.fixture() diff --git a/roles/prometheus/molecule/latest/tests/test_alternative.py b/roles/prometheus/molecule/latest/tests/test_alternative.py index 04e3fdbc..f3baca8f 100644 --- a/roles/prometheus/molecule/latest/tests/test_alternative.py +++ b/roles/prometheus/molecule/latest/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/pushgateway/molecule/alternative/tests/test_alternative.py b/roles/pushgateway/molecule/alternative/tests/test_alternative.py index baa7e5c2..a77c95c6 100644 --- a/roles/pushgateway/molecule/alternative/tests/test_alternative.py +++ b/roles/pushgateway/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/pushgateway/molecule/default/tests/test_default.py b/roles/pushgateway/molecule/default/tests/test_default.py index b7c6ed45..5fe09a4e 100644 --- a/roles/pushgateway/molecule/default/tests/test_default.py +++ b/roles/pushgateway/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/pushgateway/molecule/latest/tests/test_alternative.py b/roles/pushgateway/molecule/latest/tests/test_alternative.py index 89ccc836..117c4ae4 100644 --- a/roles/pushgateway/molecule/latest/tests/test_alternative.py +++ b/roles/pushgateway/molecule/latest/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/redis_exporter/molecule/alternative/tests/test_alternative.py b/roles/redis_exporter/molecule/alternative/tests/test_alternative.py index 4a377bb8..edc5e595 100644 --- a/roles/redis_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/redis_exporter/molecule/alternative/tests/test_alternative.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/redis_exporter/molecule/default/tests/test_default.py b/roles/redis_exporter/molecule/default/tests/test_default.py index 146e77e5..d0b80ec1 100644 --- a/roles/redis_exporter/molecule/default/tests/test_default.py +++ b/roles/redis_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/redis_exporter/molecule/latest/tests/test_latest.py b/roles/redis_exporter/molecule/latest/tests/test_latest.py index 360663e8..66132172 100644 --- a/roles/redis_exporter/molecule/latest/tests/test_latest.py +++ b/roles/redis_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/smartctl_exporter/molecule/alternative/tests/test_alternative.py b/roles/smartctl_exporter/molecule/alternative/tests/test_alternative.py index af8ba9d6..be2fee9f 100644 --- a/roles/smartctl_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/smartctl_exporter/molecule/alternative/tests/test_alternative.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/smartctl_exporter/molecule/default/tests/test_default.py b/roles/smartctl_exporter/molecule/default/tests/test_default.py index 72be4f06..37c7d26b 100644 --- a/roles/smartctl_exporter/molecule/default/tests/test_default.py +++ b/roles/smartctl_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/smartctl_exporter/molecule/latest/tests/test_latest.py b/roles/smartctl_exporter/molecule/latest/tests/test_latest.py index 3062df90..de2947cf 100644 --- a/roles/smartctl_exporter/molecule/latest/tests/test_latest.py +++ b/roles/smartctl_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/smokeping_prober/molecule/alternative/tests/test_alternative.py b/roles/smokeping_prober/molecule/alternative/tests/test_alternative.py index 96444903..4c9ea439 100644 --- a/roles/smokeping_prober/molecule/alternative/tests/test_alternative.py +++ b/roles/smokeping_prober/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/smokeping_prober/molecule/default/tests/test_default.py b/roles/smokeping_prober/molecule/default/tests/test_default.py index e80de3a5..a0ce3131 100644 --- a/roles/smokeping_prober/molecule/default/tests/test_default.py +++ b/roles/smokeping_prober/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_directories(host): diff --git a/roles/smokeping_prober/molecule/latest/tests/test_latest.py b/roles/smokeping_prober/molecule/latest/tests/test_latest.py index 9da9ec86..289c4754 100644 --- a/roles/smokeping_prober/molecule/latest/tests/test_latest.py +++ b/roles/smokeping_prober/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/snmp_exporter/molecule/alternative/tests/test_alternative.py b/roles/snmp_exporter/molecule/alternative/tests/test_alternative.py index 7c32636c..6617f522 100644 --- a/roles/snmp_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/snmp_exporter/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/snmp_exporter/molecule/default/tests/test_default.py b/roles/snmp_exporter/molecule/default/tests/test_default.py index 6715e5b0..6d292e3d 100644 --- a/roles/snmp_exporter/molecule/default/tests/test_default.py +++ b/roles/snmp_exporter/molecule/default/tests/test_default.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/snmp_exporter/molecule/latest/tests/test_latest.py b/roles/snmp_exporter/molecule/latest/tests/test_latest.py index 07d2d4ae..adf3ad06 100644 --- a/roles/snmp_exporter/molecule/latest/tests/test_latest.py +++ b/roles/snmp_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ diff --git a/roles/systemd_exporter/molecule/alternative/tests/test_alternative.py b/roles/systemd_exporter/molecule/alternative/tests/test_alternative.py index c47ea270..10b052d3 100644 --- a/roles/systemd_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/systemd_exporter/molecule/alternative/tests/test_alternative.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_service(host): diff --git a/roles/systemd_exporter/molecule/default/tests/test_default.py b/roles/systemd_exporter/molecule/default/tests/test_default.py index 392114ad..75c9cb9e 100644 --- a/roles/systemd_exporter/molecule/default/tests/test_default.py +++ b/roles/systemd_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_files(host): diff --git a/roles/systemd_exporter/molecule/latest/tests/test_latest.py b/roles/systemd_exporter/molecule/latest/tests/test_latest.py index 1f553ce8..0aa59e1c 100644 --- a/roles/systemd_exporter/molecule/latest/tests/test_latest.py +++ b/roles/systemd_exporter/molecule/latest/tests/test_latest.py @@ -2,11 +2,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type import pytest -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [