|
13 | 13 | ---
|
14 | 14 | module: lvm_pv
|
15 | 15 | short_description: Manage LVM Physical Volumes
|
16 |
| -version_added: "1.0.0" |
| 16 | +version_added: "10.7.0" |
17 | 17 | description:
|
18 |
| - - Creates, resizes or removes LVM Physical Volumes. |
| 18 | +- Creates, resizes or removes LVM Physical Volumes. |
19 | 19 | author:
|
20 |
| - - Klention Mali (@klention) |
| 20 | +- Klention Mali (@klention) |
21 | 21 | options:
|
22 | 22 | device:
|
23 | 23 | description:
|
24 |
| - - Path to the block device to manage. |
| 24 | + - Path to the block device to manage. |
25 | 25 | type: str
|
26 | 26 | required: true
|
27 | 27 | state:
|
28 | 28 | description:
|
29 |
| - - Control if the physical volume exists. |
| 29 | + - Control if the physical volume exists. |
30 | 30 | type: str
|
31 | 31 | choices: [ present, absent ]
|
32 | 32 | default: present
|
33 | 33 | force:
|
34 | 34 | description:
|
35 |
| - - Force dangerous operations (equivalent to C(pvcreate -f) or C(pvremove -ff)). |
| 35 | + - Force the operation. |
| 36 | + - When O(state=present) (creating a PV), this uses C(pvcreate -f) to force creation. |
| 37 | + - When O(state=absent) (removing a PV), this uses C(pvremove -ff) to force removal even if part of a volume group. |
36 | 38 | type: bool
|
37 | 39 | default: false
|
38 | 40 | resize:
|
39 | 41 | description:
|
40 |
| - - Resize PV to device size when O(state=present). |
| 42 | + - Resize PV to device size when O(state=present). |
41 | 43 | type: bool
|
42 | 44 | default: false
|
43 | 45 | notes:
|
44 |
| - - Requires LVM2 utilities installed on the target system. |
45 |
| - - Device path must exist when creating a PV. |
| 46 | +- Requires LVM2 utilities installed on the target system. |
| 47 | +- Device path must exist when creating a PV. |
46 | 48 | '''
|
47 | 49 |
|
48 | 50 | EXAMPLES = r'''
|
@@ -178,26 +180,19 @@ def main():
|
178 | 180 | if is_pv:
|
179 | 181 | if module.check_mode:
|
180 | 182 | changed = True
|
181 |
| - actions.append('would be removed') |
182 |
| - else: |
183 |
| - cmd = ['pvremove'] |
| 183 | + cmd = ['pvremove', '-y'] |
184 | 184 | if force:
|
185 |
| - cmd.extend(['-ff', '-y']) |
186 |
| - else: |
187 |
| - cmd.append('-y') |
| 185 | + cmd.append('-ff') |
| 186 | + |
188 | 187 | cmd.append(device)
|
189 |
| - rc, out, err = module.run_command(cmd) |
190 |
| - if rc != 0: |
191 |
| - module.fail_json(msg="Failed to remove PV: %s" % err) |
192 |
| - changed = True |
| 188 | + rc, out, err = module.run_command(cmd, check_rc=True) |
193 | 189 | actions.append('removed')
|
194 | 190 |
|
195 | 191 | # Generate final message
|
196 |
| - if not actions: |
197 |
| - msg = "No changes needed for PV %s" % device |
198 |
| - else: |
| 192 | + if actions: |
199 | 193 | msg = "PV %s: %s" % (device, ', '.join(actions))
|
200 |
| - |
| 194 | + else: |
| 195 | + msg = "No changes needed for PV %s" % device |
201 | 196 | module.exit_json(changed=changed, msg=msg)
|
202 | 197 |
|
203 | 198 |
|
|
0 commit comments