3
3
"""
4
4
5
5
import logging
6
+ import os
6
7
import shutil
7
8
import textwrap
8
9
@@ -63,22 +64,59 @@ def ansible_inventory(ansible_inventory_directory, sshd_server, known_hosts_file
63
64
return inventory
64
65
65
66
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
+
66
87
@pytest .mark .requires_sshd_server
67
88
@pytest .mark .timeout_unless_on_windows (240 )
68
89
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" )
69
93
rundir = tmp_path / "rundir"
70
94
rundir .mkdir (exist_ok = True , parents = True )
71
95
remove_contents = textwrap .dedent (
72
96
"""
73
97
---
74
98
- hosts: all
75
99
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:
78
109
name: postfix
79
110
state: absent
80
111
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'
82
120
"""
83
121
)
84
122
remove_playbook = rundir / "remove.yml"
@@ -88,12 +126,26 @@ def test_ansible_playbook(salt_call_cli, ansible_inventory, tmp_path):
88
126
---
89
127
- hosts: all
90
128
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:
93
145
name: postfix
94
146
state: present
95
147
become: true
96
- become_user: root
148
+ when: ansible_pkg_mgr == 'apt'
97
149
"""
98
150
)
99
151
install_playbook = rundir / "install.yml"
0 commit comments