Skip to content

Commit e70d2f3

Browse files
spetrosiclaude
authored andcommitted
Select mount module by managed node python version
Gate the mount tasks on ansible_facts.python_version instead of ansible_version, rename the vendored module to mount_python_27, and gather the python_version fact subset. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 440e87d commit e70d2f3

3 files changed

Lines changed: 33 additions & 31 deletions

File tree

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
DOCUMENTATION = r'''
2121
---
22-
module: mount_ansible_29
22+
module: mount_python_27
2323
short_description: Control active and configured mount points
2424
description:
2525
- This module controls active and configured mount points in C(/etc/fstab).
@@ -149,57 +149,57 @@
149149
EXAMPLES = r'''
150150
# Before 2.3, option 'name' was used instead of 'path'
151151
- name: Mount DVD read-only
152-
mount_ansible_29:
152+
mount_python_27:
153153
path: /mnt/dvd
154154
src: /dev/sr0
155155
fstype: iso9660
156156
opts: ro,noauto
157157
state: present
158158
159159
- name: Mount up device by label
160-
mount_ansible_29:
160+
mount_python_27:
161161
path: /srv/disk
162162
src: LABEL=SOME_LABEL
163163
fstype: ext4
164164
state: present
165165
166166
- name: Mount up device by UUID
167-
mount_ansible_29:
167+
mount_python_27:
168168
path: /home
169169
src: UUID=b3e48f45-f933-4c8e-a700-22a159ec9077
170170
fstype: xfs
171171
opts: noatime
172172
state: present
173173
174174
- name: Unmount a mounted volume
175-
mount_ansible_29:
175+
mount_python_27:
176176
path: /tmp/mnt-pnt
177177
state: unmounted
178178
179179
- name: Remount a mounted volume
180-
mount_ansible_29:
180+
mount_python_27:
181181
path: /tmp/mnt-pnt
182182
state: remounted
183183
184184
# The following will not save changes to fstab, and only be temporary until
185185
# a reboot, or until calling "state: unmounted" followed by "state: mounted"
186186
# on the same "path"
187187
- name: Remount a mounted volume and append exec to the existing options
188-
mount_ansible_29:
188+
mount_python_27:
189189
path: /tmp
190190
state: remounted
191191
opts: exec
192192
193193
- name: Mount and bind a volume
194-
mount_ansible_29:
194+
mount_python_27:
195195
path: /system/new_volume/boot
196196
src: /boot
197197
opts: bind
198198
state: mounted
199199
fstype: none
200200
201201
- name: Mount an NFS volume
202-
mount_ansible_29:
202+
mount_python_27:
203203
src: 192.168.1.100:/nfs/ssd/shared_data
204204
path: /mnt/shared_data
205205
opts: rw,sync,hard

‎tasks/main-blivet.yml‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@
190190
# update its view, then set up the new mounts. Otherwise,
191191
# systemd will forcibly prevent mounting a new volume to an
192192
# existing mount point.
193-
# ansible 2.9 (ansible-engine) uses the vendored mount_ansible_29 module,
194-
# since ansible.posix cannot be installed there; other systems use the bare
195-
# mount name, which redirects to the latest ansible.posix.mount.
196-
- name: Remove obsolete mounts - ansible 2.9
197-
mount_ansible_29:
193+
# On managed nodes with python 2 (EL7 with ansible 2.9, where the
194+
# ansible.posix collection cannot be installed), use the dependency-free
195+
# vendored mount_python_27 module, which retains python 2 support.
196+
- name: Remove obsolete mounts - python 2
197+
mount_python_27:
198198
src: "{{ mount_info['src'] | default(omit) }}"
199199
path: "{{ mount_info['path'] }}"
200200
fstype: "{{ mount_info['fstype'] | default(omit) }}"
@@ -204,12 +204,12 @@
204204
selectattr('state', 'match', '^absent$') | list }}"
205205
loop_control:
206206
loop_var: mount_info
207-
when: ansible_version.full is version('2.10', '<')
207+
when: ansible_facts['python_version'] is version('3', '<')
208208

209-
# Bare module name (not FQCN): on ansible 2.9 the collection is not
210-
# installable and an unresolvable FQCN aborts play parsing even for a task
211-
# skipped by "when". The bare name resolves to the ansible 2.9 builtin
212-
# (skipped here) and redirects to the latest collection module elsewhere.
209+
# Bare module name (not FQCN): an unresolvable FQCN aborts play parsing on
210+
# ansible 2.9 even for a task skipped by "when", so the bare name is used.
211+
# This runs only on managed nodes with python 3, where the bare name resolves
212+
# to the latest ansible.posix.mount.
213213
- name: Remove obsolete mounts
214214
mount: # noqa fqcn
215215
src: "{{ mount_info['src'] | default(omit) }}"
@@ -221,18 +221,18 @@
221221
selectattr('state', 'match', '^absent$') | list }}"
222222
loop_control:
223223
loop_var: mount_info
224-
when: ansible_version.full is version('2.10', '>=')
224+
when: ansible_facts['python_version'] is version('3', '>=')
225225

226226
- name: Tell systemd to refresh its view of /etc/fstab
227227
systemd:
228228
daemon_reload: true
229229
when: blivet_output['mounts'] | length > 0
230230

231-
# ansible 2.9 (ansible-engine) uses the vendored mount_ansible_29 module,
232-
# since ansible.posix cannot be installed there; other systems use the bare
233-
# mount name, which redirects to the latest ansible.posix.mount.
234-
- name: Set up new/current mounts - ansible 2.9
235-
mount_ansible_29:
231+
# On managed nodes with python 2 (EL7 with ansible 2.9, where the
232+
# ansible.posix collection cannot be installed), use the dependency-free
233+
# vendored mount_python_27 module, which retains python 2 support.
234+
- name: Set up new/current mounts - python 2
235+
mount_python_27:
236236
src: "{{ mount_info['src'] | default(omit) }}"
237237
path: "{{ mount_info['path'] }}"
238238
fstype: "{{ mount_info['fstype'] | default(omit) }}"
@@ -242,12 +242,12 @@
242242
rejectattr('state', 'match', '^absent$') | list }}"
243243
loop_control:
244244
loop_var: mount_info
245-
when: ansible_version.full is version('2.10', '<')
245+
when: ansible_facts['python_version'] is version('3', '<')
246246

247-
# Bare module name (not FQCN): on ansible 2.9 the collection is not
248-
# installable and an unresolvable FQCN aborts play parsing even for a task
249-
# skipped by "when". The bare name resolves to the ansible 2.9 builtin
250-
# (skipped here) and redirects to the latest collection module elsewhere.
247+
# Bare module name (not FQCN): an unresolvable FQCN aborts play parsing on
248+
# ansible 2.9 even for a task skipped by "when", so the bare name is used.
249+
# This runs only on managed nodes with python 3, where the bare name resolves
250+
# to the latest ansible.posix.mount.
251251
- name: Set up new/current mounts
252252
mount: # noqa fqcn
253253
src: "{{ mount_info['src'] | default(omit) }}"
@@ -259,7 +259,7 @@
259259
rejectattr('state', 'match', '^absent$') | list }}"
260260
loop_control:
261261
loop_var: mount_info
262-
when: ansible_version.full is version('2.10', '>=')
262+
when: ansible_facts['python_version'] is version('3', '>=')
263263

264264
- name: Manage mount ownership/permissions
265265
file:

‎vars/main.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ __storage_required_facts:
77
- distribution_version
88
- os_family
99
- pkg_mgr
10+
# provides ansible_facts.python_version, used to pick the mount module
11+
- python_version
1012

1113
# the subsets of ansible_facts that need to be gathered in case any of the
1214
# facts in required_facts is missing; see the documentation of

0 commit comments

Comments
 (0)