Skip to content

Commit

Permalink
rename roles to snapshot_action
Browse files Browse the repository at this point in the history
  • Loading branch information
swapdisk committed Jan 9, 2024
1 parent 507ddf3 commit a635b23
Show file tree
Hide file tree
Showing 20 changed files with 123 additions and 123 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ This collection depends on the following collections
These are the roles included in the collection. Follow the links below to see the detailed documentation and example playbooks for each role.
- [`create_snapshot`](./roles/create_snapshot/) - controls the creation for a defined set of LVM snapshot volumes
- [`remove_snapshot`](./roles/remove_snapshot/) - used to remove snapshots previously created using the `create_snapshot` role
- [`revert_snapshot`](./roles/revert_snapshot/) - used to revert to snapshots previously created using the `create_snapshot` role
- [`snapshot_create`](./roles/snapshot_create/) - controls the creation for a defined set of LVM snapshot volumes
- [`snapshot_remove`](./roles/snapshot_remove/) - used to remove snapshots previously created using the `snapshot_create` role
- [`snapshot_revert`](./roles/snapshot_revert/) - used to revert to snapshots previously created using the `snapshot_create` role
- [`shrink_lv`](./roles/shrink_lv/) - controls decreasing logical volume size along with the filesystem
- [`bigboot`](./roles/bigboot/) - controls increasing of the boot partition while moving, and shrinking if needed, the adjacent partition
- [`initramfs`](./roles/initramfs/) - controls the atomic flow of building and using a temporary initramfs in a reboot and restoring the original one
Expand Down
2 changes: 1 addition & 1 deletion changelogs/fragments/split-lvm-snapshot_role.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
breaking_changes:
- Split lvm_snapshots role into create_snapshot, revert_snapshot and remove_snapshot
- Split lvm_snapshots role into snapshot_create, snapshot_revert and snapshot_remove
40 changes: 20 additions & 20 deletions roles/snapshot_create/README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
# create_snapshot role
# snapshot_create role


The `create_snapshot` role is used to control the creation for a defined set of LVM snapshot volumes.
The `snapshot_create` 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 will verify free space and should fail if there is not enough or if any snapshots already exist for the given `snapshot_create_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`
### `snapshot_create_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`
### `snapshot_create_set_name`

The variable `create_snapshot_set_name` is used to identify the list of volumes to be operated upon.
The variable `snapshot_create_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>`
`<Origin LV name>_<snapshot_create_set_name>`

### `create_snapshot_boot_backup`
### `snapshot_create_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`.
The files are preserved in a compressed tar archive at `/root/boot-backup-<snapshot_create_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`
### `snapshot_create_snapshot_autoextend_threshold`

Configure the given `create_snapshot_autoextend_threshold` setting in lvm.conf before creating snapshots.
Configure the given `snapshot_create_autoextend_threshold` setting in lvm.conf before creating snapshots.

### `create_snapshot_snapshot_autoextend_percent`
### `snapshot_create_snapshot_autoextend_percent`

Configure the given `create_snapshot_snapshot_autoextend_percent` setting in lvm.conf before creating snapshots.
Configure the given `snapshot_create_snapshot_autoextend_percent` setting in lvm.conf before creating snapshots.

### `create_snapshot_volumes`
### `snapshot_create_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.

Expand Down Expand Up @@ -69,12 +69,12 @@ 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:
- name: snapshot_create
snapshot_create_set_name: ripu
snapshot_create_snapshot_autoextend_threshold: 70
snapshot_create_snapshot_autoextend_percent: 20
snapshot_create_boot_backup: true
snapshot_create_volumes:
- vg: rootvg
lv: root
size: 2G
Expand Down
4 changes: 2 additions & 2 deletions roles/snapshot_create/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
create_snapshot_volumes: []
create_snapshot_boot_backup: false
snapshot_create_volumes: []
snapshot_create_boot_backup: false
14 changes: 7 additions & 7 deletions roles/snapshot_create/tasks/check.yml
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: "{{ create_snapshot_volumes }}"
loop: "{{ snapshot_create_volumes }}"

- name: Verify that there are no existing snapshots
ansible.builtin.include_tasks: verify_no_existing_snapshot.yml
loop: "{{ create_snapshot_volumes }}"
loop: "{{ snapshot_create_volumes }}"

- name: Verify that there is enough storage space
ansible.builtin.script: check.py snapshots '{{ create_snapshot_volumes | to_json }}'
ansible.builtin.script: check.py snapshots '{{ snapshot_create_volumes | to_json }}'
args:
executable: "{{ ansible_python.executable }}"
register: create_snapshot_check_status
register: snapshot_create_check_status
failed_when: false
changed_when: false

- name: Store check return in case of failure
ansible.builtin.set_fact:
create_snapshot_check_failure_json: "{{ create_snapshot_check_status.stdout | from_json }}"
when: create_snapshot_check_status.rc != 0
snapshot_create_check_failure_json: "{{ snapshot_create_check_status.stdout | from_json }}"
when: snapshot_create_check_status.rc != 0

- name: Assert results
ansible.builtin.assert:
that: create_snapshot_check_status.rc == 0
that: snapshot_create_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
30 changes: 15 additions & 15 deletions roles/snapshot_create/tasks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
block:
- name: Stringify snapshot_autoextend_percent setting
ansible.builtin.set_fact:
create_snapshot_snapshot_autoextend_percent_config: "activation/snapshot_autoextend_percent={{ create_snapshot_snapshot_autoextend_percent }}"
when: create_snapshot_snapshot_autoextend_percent is defined
snapshot_create_snapshot_autoextend_percent_config: "activation/snapshot_autoextend_percent={{ snapshot_create_snapshot_autoextend_percent }}"
when: snapshot_create_snapshot_autoextend_percent is defined
- name: Stringify snapshot_autoextend_threshold setting
ansible.builtin.set_fact:
create_snapshot_snapshot_autoextend_threshold_config: "activation/snapshot_autoextend_threshold={{ create_snapshot_snapshot_autoextend_threshold }}"
when: create_snapshot_snapshot_autoextend_threshold is defined
snapshot_create_snapshot_autoextend_threshold_config: "activation/snapshot_autoextend_threshold={{ snapshot_create_snapshot_autoextend_threshold }}"
when: snapshot_create_snapshot_autoextend_threshold is defined
- name: Stringify the new config
ansible.builtin.set_fact:
create_snapshot_new_lvm_config: >
{{ create_snapshot_snapshot_autoextend_percent_config | default('') }}
{{ create_snapshot_snapshot_autoextend_threshold_config | default('') }}
snapshot_create_new_lvm_config: >
{{ snapshot_create_snapshot_autoextend_percent_config | default('') }}
{{ snapshot_create_snapshot_autoextend_threshold_config | default('') }}
- name: Set LVM configuration
ansible.builtin.command: 'lvmconfig --mergedconfig --config "{{ create_snapshot_new_lvm_config }}" --file /etc/lvm/lvm.conf'
ansible.builtin.command: 'lvmconfig --mergedconfig --config "{{ snapshot_create_new_lvm_config }}" --file /etc/lvm/lvm.conf'
changed_when: true
when: ((create_snapshot_new_lvm_config | trim) | length) > 0
when: ((snapshot_create_new_lvm_config | trim) | length) > 0

- name: Check for grubenv saved_entry
ansible.builtin.lineinfile:
Expand All @@ -26,20 +26,20 @@
check_mode: true
changed_when: false
failed_when: false
register: create_snapshot_grubenv
register: snapshot_create_grubenv

- name: Add grubenv saved_entry
ansible.builtin.shell: 'grubby --set-default-index=$(grubby --default-index)'
changed_when: true
when: create_snapshot_grubenv.found is defined and create_snapshot_grubenv.found == 0
when: snapshot_create_grubenv.found is defined and snapshot_create_grubenv.found == 0

- name: Create snapshots
community.general.lvol:
vg: "{{ item.vg }}"
lv: "{{ item.lv }}"
snapshot: "{{ item.lv }}_{{ create_snapshot_set_name }}"
snapshot: "{{ item.lv }}_{{ snapshot_create_set_name }}"
size: "{{ item.size | default(omit) }}"
loop: "{{ create_snapshot_volumes }}"
loop: "{{ snapshot_create_volumes }}"

- name: Required packages are present
ansible.builtin.package:
Expand All @@ -52,7 +52,7 @@
community.general.archive:
format: gz
mode: '0644'
dest: "/root/boot-backup-{{ create_snapshot_set_name }}.tgz"
dest: "/root/boot-backup-{{ snapshot_create_set_name }}.tgz"
path:
- "/boot/initramfs-{{ ansible_kernel }}.img"
- "/boot/vmlinuz-{{ ansible_kernel }}"
Expand All @@ -65,4 +65,4 @@
- /boot/grub2/grubenv
- /boot/loader/entries
- /boot/efi/EFI/redhat/grub.cfg
when: create_snapshot_boot_backup
when: snapshot_create_boot_backup
4 changes: 2 additions & 2 deletions roles/snapshot_create/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

- name: Create Snapshot
vars:
create_snapshot_volumes: "{{ create_snapshot_check_status.stdout | from_json }}"
snapshot_create_volumes: "{{ snapshot_create_check_status.stdout | from_json }}"
ansible.builtin.include_tasks: create.yml
when: not (create_snapshot_check_only | default(false))
when: not (snapshot_create_check_only | default(false))
10 changes: 5 additions & 5 deletions roles/snapshot_create/tasks/verify_no_existing_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
lvs
--select 'vg_name = {{ item.vg }}
&& origin = {{ item.lv }}
&& lv_name = {{ item.lv }}_{{ create_snapshot_set_name }}'
&& lv_name = {{ item.lv }}_{{ snapshot_create_set_name }}'
--reportformat json
register: create_snapshot_lvs_response
register: snapshot_create_lvs_response
changed_when: false

- name: Parse report
ansible.builtin.set_fact:
create_snapshot_lv_snapshot_report_array: "{{ (create_snapshot_lvs_response.stdout | from_json).report[0].lv }}"
snapshot_create_lv_snapshot_report_array: "{{ (snapshot_create_lvs_response.stdout | from_json).report[0].lv }}"

- name: Verify that the no snapshot exists for the volume
ansible.builtin.assert:
that: (create_snapshot_lv_snapshot_report_array | length) == 0
that: (snapshot_create_lv_snapshot_report_array | length) == 0
fail_msg: >
The volume '{{ item.lv }}' in volume group '{{ item.vg }}'
already has at least one snapshot
'{{ create_snapshot_lv_snapshot_report_array[0].lv_name | default('none') }}'
'{{ snapshot_create_lv_snapshot_report_array[0].lv_name | default('none') }}'
4 changes: 2 additions & 2 deletions roles/snapshot_create/tasks/verify_volume_exists.yml
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: create_snapshot_lvs_response
register: snapshot_create_lvs_response
changed_when: false

- name: Verify that the volume was found
ansible.builtin.assert:
that: (((create_snapshot_lvs_response.stdout | from_json).report[0].lv) | length) > 0
that: (((snapshot_create_lvs_response.stdout | from_json).report[0].lv) | length) > 0
fail_msg: "Could not find volume '{{ item.lv }}' in volume group '{{ item.vg }}'"
16 changes: 8 additions & 8 deletions roles/snapshot_remove/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# remove_snapshot role
# snapshot_remove role

The `remove_snapshot` role is used to remove snapshots.
The `snapshot_remove` role is used to remove snapshots.
In addition, it removes the Grub configuration and image files under /boot if it was previously backed up
It is intended to be used along with the `create_snapshot` role.
It is intended to be used along with the `snapshot_create` role.

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

### `remove_snapshot_set_name`
### `snapshot_remove_set_name`

The variable `remove_snapshot_set_name` is used to identify the list of volumes to be operated upon.
The variable `snapshot_remove_set_name` is used to identify the list of volumes to be operated upon.
The role will use the following naming convention when reverting the snapshots:

`<Origin LV name>_<remove_snapshot_set_name>`
`<Origin LV name>_<snapshot_remove_set_name>`

This naming convention will be used to identify the snapshots to be removed.

Expand All @@ -27,6 +27,6 @@ Each snapshot in the snapshot set is removed and the backed up image files from
```yaml
- hosts: all
roles:
- name: remove_snapshot
remove_snapshot_set_name: ripu
- name: snapshot_remove
snapshot_remove_set_name: ripu
```
10 changes: 5 additions & 5 deletions roles/snapshot_remove/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
- name: Calculate the list of snapshots
block:
- name: Get list of volumes
ansible.builtin.command: "lvs --select 'lv_name =~ {{ remove_snapshot_set_name }}$ && origin != \"\"' --reportformat json "
register: remove_snapshot_lvs_response
ansible.builtin.command: "lvs --select 'lv_name =~ {{ snapshot_remove_set_name }}$ && origin != \"\"' --reportformat json "
register: snapshot_remove_lvs_response
changed_when: false
- name: Get LV dict List
ansible.builtin.set_fact:
remove_snapshot_snapshots: "{{ (remove_snapshot_lvs_response.stdout | from_json).report[0].lv }}"
snapshot_remove_snapshots: "{{ (snapshot_remove_lvs_response.stdout | from_json).report[0].lv }}"

- name: Remove snapshots
community.general.lvol:
Expand All @@ -15,9 +15,9 @@
lv: "{{ item.origin }}"
snapshot: "{{ item.lv_name }}"
force: true
loop: "{{ remove_snapshot_snapshots }}"
loop: "{{ snapshot_remove_snapshots }}"

- name: Remove boot backup
ansible.builtin.file:
path: "/root/boot-backup-{{ remove_snapshot_set_name }}.tgz"
path: "/root/boot-backup-{{ snapshot_remove_set_name }}.tgz"
state: absent
18 changes: 9 additions & 9 deletions roles/snapshot_revert/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# revert_snapshot role
# snapshot_revert role


The `revert_snapshot` role is used to merge snapshots to origin and reboot (i.e., rollback).
The `snapshot_revert` role is used to merge snapshots to origin and reboot (i.e., rollback).
The role will verify that all snapshots in the set are still in active state before doing any merges.
This is to prevent rolling back if any snapshots have become invalidated in which case the role should fail.
In addition, it restores the Grub configuration and image files under /boot is it was previously backed up
It is intended to be used along with the `create_snapshot` role.
It is intended to be used along with the `snapshot_create` role.

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

### `revert_snapshot_set_name`
### `snapshot_revert_set_name`

The variable `revert_snapshot_set_name` is used to identify the list of volumes to be operated upon.
The variable `snapshot_revert_set_name` is used to identify the list of volumes to be operated upon.
The role will use the following naming convention when reverting the snapshots:

`<Origin LV name>_<revert_snapshot_set_name>`
`<Origin LV name>_<snapshot_revert_set_name>`

This naming convention will be used to identify the snapshots to be merged.

The `revert` action will verify that all snapshots in the set are still active state before doing any merges. This is to prevent rolling back if any snapshots have become invalidated in which case the `revert` action should fail.

## Example Playbooks

This playbook rolls back the host using the snapshots created using the `create_snapshot` role.
This playbook rolls back the host using the snapshots created using the `snapshot_create` role.
After verifying that all snapshots are still valid, each logical volume in the snapshot set is merged.
The image files under /boot will be restored and then the host will be rebooted.

```yaml
- hosts: all
roles:
- name: revert_snapshot
revert_snapshot_set_name: ripu
- name: snapshot_revert
snapshot_revert_set_name: ripu
```
Loading

0 comments on commit a635b23

Please sign in to comment.