Skip to content

Commit 729ff7a

Browse files
committed
Fix ansible tests
1 parent 5ecbdeb commit 729ff7a

File tree

1 file changed

+58
-6
lines changed

1 file changed

+58
-6
lines changed

tests/pytests/integration/states/test_ansiblegate.py

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import logging
6+
import os
67
import shutil
78
import textwrap
89

@@ -63,22 +64,59 @@ def ansible_inventory(ansible_inventory_directory, sshd_server, known_hosts_file
6364
return inventory
6465

6566

67+
def is_rocky_linux_8():
68+
# ansible.builtin.dnf doesn't work with Rocky Linux 8 because ansible-core
69+
# doesn't support Python 3.6 and lower starting with version 2.17
70+
if os.path.exists("/etc/os-release"):
71+
os_release_info = {}
72+
with salt.utils.files.fopen("/etc/os-release") as f:
73+
lines = f.readlines()
74+
for line in lines:
75+
if "=" in line:
76+
key, value = line.strip().split("=", 1)
77+
os_release_info[key] = value.strip('"')
78+
79+
if (
80+
os_release_info.get("ID") == "rocky"
81+
and os_release_info.get("VERSION_ID") == "8"
82+
):
83+
return True
84+
return False
85+
86+
6687
@pytest.mark.requires_sshd_server
6788
@pytest.mark.timeout_unless_on_windows(240)
6889
def test_ansible_playbook(salt_call_cli, ansible_inventory, tmp_path):
90+
found_rocky = is_rocky_linux_8()
91+
if found_rocky:
92+
pytest.skip("ansible-core doesn't support dnf on Rocky Linux 8")
6993
rundir = tmp_path / "rundir"
7094
rundir.mkdir(exist_ok=True, parents=True)
7195
remove_contents = textwrap.dedent(
7296
"""
7397
---
7498
- hosts: all
7599
tasks:
76-
- name: remove postfix
77-
yum:
100+
- name: remove postfix dnf
101+
ansible.builtin.dnf:
102+
name: postfix
103+
state: absent
104+
become: true
105+
when: ansible_pkg_mgr == 'dnf'
106+
107+
- name: remove postfix yum
108+
ansible.builtin.yum:
78109
name: postfix
79110
state: absent
80111
become: true
81-
become_user: root
112+
when: ansible_pkg_mgr == 'yum'
113+
114+
- name: remove postfix apt
115+
ansible.builtin.apt:
116+
name: postfix
117+
state: absent
118+
become: true
119+
when: ansible_pkg_mgr == 'apt'
82120
"""
83121
)
84122
remove_playbook = rundir / "remove.yml"
@@ -88,12 +126,26 @@ def test_ansible_playbook(salt_call_cli, ansible_inventory, tmp_path):
88126
---
89127
- hosts: all
90128
tasks:
91-
- name: install postfix
92-
yum:
129+
- name: install postfix dnf
130+
ansible.builtin.dnf:
131+
name: postfix
132+
state: present
133+
become: true
134+
when: ansible_pkg_mgr == 'dnf'
135+
136+
- name: install postfix yum
137+
ansible.builtin.yum:
138+
name: postfix
139+
state: present
140+
become: true
141+
when: ansible_pkg_mgr == 'yum'
142+
143+
- name: install postfix apt
144+
ansible.builtin.apt:
93145
name: postfix
94146
state: present
95147
become: true
96-
become_user: root
148+
when: ansible_pkg_mgr == 'apt'
97149
"""
98150
)
99151
install_playbook = rundir / "install.yml"

0 commit comments

Comments
 (0)