Skip to content

Commit

Permalink
refactor: do not need separate action files
Browse files Browse the repository at this point in the history
The separate action files are not needed.  I wanted to get rid
of the `STDERR` message that appeared for every command.  I had
to add `no_log: true` to the snapshot_cmd, then have additional
error handling.  Rather than apply this to every action file,
I just did this in tasks/main.yml and got rid of the individual
action files.

I also fixed some errors and formatting in the tests.

Signed-off-by: Rich Megginson <[email protected]>
  • Loading branch information
richm committed Feb 15, 2024
1 parent 665ac69 commit 7b10011
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 123 deletions.
6 changes: 0 additions & 6 deletions tasks/check.yml

This file was deleted.

7 changes: 0 additions & 7 deletions tasks/extend.yml

This file was deleted.

22 changes: 0 additions & 22 deletions tasks/list.yml

This file was deleted.

58 changes: 21 additions & 37 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,26 @@
use: "{{ (__snapshot_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"

- name: Check for space and name problems
ansible.builtin.include_tasks: check.yml
when: snapshot_lvm_action == "check" and not snapshot_lvm_verify_only

- name: Verify Complete
ansible.builtin.include_tasks: verify_complete.yml
when: snapshot_lvm_action == "check" and snapshot_lvm_verify_only

- name: Snapshot Volumes
ansible.builtin.include_tasks: snapshot.yml
when: snapshot_lvm_action == "snapshot"

- name: Remove Snapshots
ansible.builtin.include_tasks: remove.yml
when: snapshot_lvm_action == "remove" and not snapshot_lvm_verify_only

- name: Verify Remove
ansible.builtin.include_tasks: verify_remove.yml
when: snapshot_lvm_action == "remove" and snapshot_lvm_verify_only

- name: Revert to Snapshot
ansible.builtin.include_tasks: revert.yml
when: snapshot_lvm_action == "revert"

- name: List Snapshot Attributes
ansible.builtin.include_tasks: list.yml
- name: Run snapshot command {{ snapshot_lvm_action }}
ansible.builtin.script: "{{ __snapshot_cmd }}"
args:
executable: "{{ __snapshot_python }}"
register: snapshot_cmd
no_log: true
ignore_errors: true # noqa: ignore-errors - handled below

- name: Print out response
debug:
var: snapshot_cmd.stdout
verbosity: 2

- name: Set snapshot_facts to the JSON results
set_fact:
snapshot_facts: "{{ snapshot_cmd.stdout | from_json }}"
when: snapshot_lvm_action == "list"

- name: Extend Snapshots
ansible.builtin.include_tasks: extend.yml
when: snapshot_lvm_action == "extend"

- name: Mount Snapshots or Origin
ansible.builtin.include_tasks: mount.yml
when: snapshot_lvm_action == "mount"

- name: Unmount Snapshots or Origin
ansible.builtin.include_tasks: umount.yml
when: snapshot_lvm_action == "umount"
- name: Show errors
debug:
msg: "{{ snapshot_cmd.stderr }}"
when: snapshot_cmd.rc != 0
failed_when: snapshot_cmd.rc != 0
7 changes: 0 additions & 7 deletions tasks/mount.yml

This file was deleted.

7 changes: 0 additions & 7 deletions tasks/remove.yml

This file was deleted.

7 changes: 0 additions & 7 deletions tasks/revert.yml

This file was deleted.

6 changes: 0 additions & 6 deletions tasks/snapshot.yml

This file was deleted.

7 changes: 0 additions & 7 deletions tasks/umount.yml

This file was deleted.

6 changes: 0 additions & 6 deletions tasks/verify_complete.yml

This file was deleted.

6 changes: 0 additions & 6 deletions tasks/verify_remove.yml

This file was deleted.

2 changes: 1 addition & 1 deletion tests/tests_mount_verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
name: linux-system-roles.snapshot
vars:
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_action: ummountount
snapshot_lvm_action: mount
snapshot_lvm_vg: test_vg1
snapshot_lvm_lv: lv2
snapshot_lvm_mountpoint: /mnt/lv2_mp
Expand Down
5 changes: 1 addition & 4 deletions tests/tests_umount_verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,17 @@
snapshot_lvm_mountpoint: /mnt/lv1_mp
snapshot_lvm_verify_only: true


- name: Verify snapshot is mounted for lv2
include_role:
name: linux-system-roles.snapshot
vars:
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_action: ummountount
snapshot_lvm_action: mount
snapshot_lvm_vg: test_vg1
snapshot_lvm_lv: lv2
snapshot_lvm_mountpoint: /mnt/lv2_mp
snapshot_lvm_verify_only: true


- name: Verify snapshot is mounted for lv7
include_role:
name: linux-system-roles.snapshot
Expand Down Expand Up @@ -210,7 +208,6 @@
snapshot_lvm_action: umount
snapshot_lvm_mountpoint: /mnt/lv6_mp


- name: Run the snapshot role remove the snapshot LVs
include_role:
name: linux-system-roles.snapshot
Expand Down

0 comments on commit 7b10011

Please sign in to comment.