-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split lvm_snapshots role into separate roles (#40)
Split into three roles - create, revert and remove For create allow running only check Do not use check_for_resize as the functionality was moved to shrink_lv Signed-off-by: Ygal Blum <[email protected]>
- Loading branch information
Showing
28 changed files
with
318 additions
and
368 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,2 @@ | ||
breaking_changes: | ||
- Split lvm_snapshots role into create_snapshot, revert_snapshot and remove_snapshot |
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,84 @@ | ||
# create_snapshot role | ||
|
||
|
||
The `create_snapshot` role is used to control the creation for a defined set of LVM snapshot volumes. | ||
In addition, it can optionally save the Grub configuration and image files under /boot and configure settings to enable the LVM snapshot autoextend capability. | ||
The role will verify free space and should fail if there is not enough or if any snapshots already exist for the given `create_snapshot_set_name`. | ||
|
||
The role is designed to support the automation of RHEL in-place upgrades, but can also be used to reduce the risk of more mundane system maintenance activities. | ||
|
||
## Role Variables | ||
|
||
### `create_snapshot_check_only` | ||
|
||
When set to `true` the role will only verify there is enough free space for the specified snapshots and not create them. | ||
Default `false` | ||
|
||
### `create_snapshot_set_name` | ||
|
||
The variable `create_snapshot_set_name` is used to identify the list of volumes to be operated upon. | ||
The role will use the following naming convention when creating the snapshots: | ||
|
||
`<Origin LV name>_<create_snapshot_set_name>` | ||
|
||
### `create_snapshot_boot_backup` | ||
|
||
Boolean to specify that the role should preserve the Grub configuration and image files under /boot required for booting the default kernel. | ||
The files are preserved in a compressed tar archive at `/root/boot-backup-<create_snapshot_set_name>.tgz`. Default is `false`. | ||
|
||
> **Warning** | ||
> | ||
> When automating RHEL in-place upgrades, do not perform a Grub to Grub2 migration as part of your upgrade playbook. It will invalidate your boot backup and cause a subsequent `revert` action to fail. For example, if you are using the [`upgrade`](https://github.com/redhat-cop/infra.leapp/tree/main/roles/upgrade#readme) role from the [`infra.leapp`](https://github.com/redhat-cop/infra.leapp) collection, do not set `update_grub_to_grub_2` to `true`. Grub to Grub2 migration should only be performed after the `remove` action has been performed to delete the snapshots and boot backup. | ||
### `create_snapshot_snapshot_autoextend_threshold` | ||
|
||
Configure the given `create_snapshot_autoextend_threshold` setting in lvm.conf before creating snapshots. | ||
|
||
### `create_snapshot_snapshot_autoextend_percent` | ||
|
||
Configure the given `create_snapshot_snapshot_autoextend_percent` setting in lvm.conf before creating snapshots. | ||
|
||
### `create_snapshot_volumes` | ||
|
||
This is the list of logical volumes for which snapshots are to be created and the size requirements for those snapshots. The volumes list is only required when the role is run with the check or create action. | ||
|
||
### `vg` | ||
|
||
The volume group of the origin logical volume for which a snapshot will be created. | ||
|
||
### `lv` | ||
|
||
The origin logical volume for which a snapshot will be created. | ||
|
||
### `size` | ||
|
||
The size of the logical volume according to the definition of the | ||
[size](https://docs.ansible.com/ansible/latest/collections/community/general/lvol_module.html#parameter-size) | ||
parameter of the `community.general.lvol` module. | ||
|
||
To create thin provisioned snapshot of a thin provisioned volume, omit the `size` parameter or set it to `0` | ||
|
||
## Example Playbooks | ||
|
||
Perform space check and fail of there will not be enough space for all the snapshots in the set. | ||
If there is sufficient space, proceed to create snapshots for the listed logical volumes. | ||
Each snapshot will be sized to 20% of the origin volume size. | ||
Snapshot autoextend settings are configured to enable free space in the volume group to be allocated to any snapshot that may exceed 70% usage in the future. | ||
Files under /boot will be preserved. | ||
|
||
```yaml | ||
- hosts: all | ||
roles: | ||
- name: create_snapshot | ||
create_snapshot_set_name: ripu | ||
create_snapshot_snapshot_autoextend_threshold: 70 | ||
create_snapshot_snapshot_autoextend_percent: 20 | ||
create_snapshot_boot_backup: true | ||
create_snapshot_volumes: | ||
- vg: rootvg | ||
lv: root | ||
size: 2G | ||
- vg: rootvg | ||
lv: var | ||
size: 2G | ||
``` |
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,2 @@ | ||
create_snapshot_volumes: [] | ||
create_snapshot_boot_backup: false |
File renamed without changes.
14 changes: 7 additions & 7 deletions
14
roles/lvm_snapshots/tasks/check.yml → roles/create_snapshot/tasks/check.yml
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 |
---|---|---|
@@ -1,26 +1,26 @@ | ||
- name: Verify that all volumes exist | ||
ansible.builtin.include_tasks: verify_volume_exists.yml | ||
loop: "{{ lvm_snapshots_volumes }}" | ||
loop: "{{ create_snapshot_volumes }}" | ||
|
||
- name: Verify that there are no existing snapshots | ||
ansible.builtin.include_tasks: verify_no_existing_snapshot.yml | ||
loop: "{{ lvm_snapshots_volumes }}" | ||
loop: "{{ create_snapshot_volumes }}" | ||
|
||
- name: Verify that there is enough storage space | ||
ansible.builtin.script: check.py snapshots '{{ lvm_snapshots_volumes | to_json }}' | ||
ansible.builtin.script: check.py snapshots '{{ create_snapshot_volumes | to_json }}' | ||
args: | ||
executable: "{{ ansible_python.executable }}" | ||
register: lvm_snapshots_check_status | ||
register: create_snapshot_check_status | ||
failed_when: false | ||
changed_when: false | ||
|
||
- name: Store check return in case of failure | ||
ansible.builtin.set_fact: | ||
lvm_snapshots_check_failure_json: "{{ lvm_snapshots_check_status.stdout | from_json }}" | ||
when: lvm_snapshots_check_status.rc != 0 | ||
create_snapshot_check_failure_json: "{{ create_snapshot_check_status.stdout | from_json }}" | ||
when: create_snapshot_check_status.rc != 0 | ||
|
||
- name: Assert results | ||
ansible.builtin.assert: | ||
that: lvm_snapshots_check_status.rc == 0 | ||
that: create_snapshot_check_status.rc == 0 | ||
fail_msg: Not enough space in the Volume Groups to create the requested snapshots | ||
success_msg: The Volume Groups have enough space to create the requested snapshots |
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,8 @@ | ||
- name: Check available disk space | ||
ansible.builtin.include_tasks: check.yml | ||
|
||
- name: Create Snapshot | ||
vars: | ||
create_snapshot_volumes: "{{ create_snapshot_check_status.stdout | from_json }}" | ||
ansible.builtin.include_tasks: create.yml | ||
when: not (create_snapshot_check_only | default(false)) |
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
4 changes: 2 additions & 2 deletions
4
..._snapshots/tasks/verify_volume_exists.yml → ...e_snapshot/tasks/verify_volume_exists.yml
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
- name: Run lvs | ||
ansible.builtin.command: "lvs --select 'vg_name = {{ item.vg }} && lv_name = {{ item.lv }}' --reportformat json" | ||
register: lvm_snapshots_lvs_response | ||
register: create_snapshot_lvs_response | ||
changed_when: false | ||
|
||
- name: Verify that the volume was found | ||
ansible.builtin.assert: | ||
that: (((lvm_snapshots_lvs_response.stdout | from_json).report[0].lv) | length) > 0 | ||
that: (((create_snapshot_lvs_response.stdout | from_json).report[0].lv) | length) > 0 | ||
fail_msg: "Could not find volume '{{ item.lv }}' in volume group '{{ item.vg }}'" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.