-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: skip running testinfra on excluded ansible versions
Signed-off-by: gardar <[email protected]>
- Loading branch information
Showing
66 changed files
with
197 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
6 changes: 2 additions & 4 deletions
6
roles/alertmanager/molecule/alternative/tests/test_alternative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
roles/bind_exporter/molecule/alternative/tests/test_alternative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
roles/blackbox_exporter/molecule/alternative/tests/test_alternative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
roles/blackbox_exporter/molecule/default/tests/test_default.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
roles/cadvisor/molecule/alternative/tests/test_alternative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
roles/chrony_exporter/molecule/alternative/tests/test_alternative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
roles/chrony_exporter/molecule/latest/tests/test_alternative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
roles/fail2ban_exporter/molecule/alternative/tests/test_alternative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
roles/fail2ban_exporter/molecule/default/tests/test_default.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
roles/ipmi_exporter/molecule/alternative/tests/test_alternative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
roles/memcached_exporter/molecule/alternative/tests/test_alternative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.