2020-10-26 19:43:01 +01:00
|
|
|
---
|
2022-08-05 14:03:38 +02:00
|
|
|
# Copyright (c) Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-10-26 19:43:01 +01:00
|
|
|
# We assume 'create_fs' tests have passed.
|
|
|
|
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Create filesystem"
|
|
|
|
community.general.filesystem:
|
2020-10-26 19:43:01 +01:00
|
|
|
dev: '{{ dev }}'
|
|
|
|
fstype: '{{ fstype }}'
|
|
|
|
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Get filesystem UUID with 'blkid'"
|
2021-07-10 16:37:31 +02:00
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: "{{ get_uuid_cmd }}"
|
2020-10-26 19:43:01 +01:00
|
|
|
changed_when: false
|
|
|
|
register: blkid_ref
|
|
|
|
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Assert that a filesystem exists on top of the device"
|
|
|
|
ansible.builtin.assert:
|
2020-10-26 19:43:01 +01:00
|
|
|
that:
|
|
|
|
- blkid_ref.stdout | length > 0
|
|
|
|
|
|
|
|
|
|
|
|
# Test check_mode first
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Remove filesystem (check mode)"
|
|
|
|
community.general.filesystem:
|
2020-10-26 19:43:01 +01:00
|
|
|
dev: '{{ dev }}'
|
|
|
|
state: absent
|
|
|
|
register: wipefs
|
2023-02-15 22:55:23 +01:00
|
|
|
check_mode: true
|
2020-10-26 19:43:01 +01:00
|
|
|
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Get filesystem UUID with 'blkid' (should remain the same)"
|
2021-07-10 16:37:31 +02:00
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: "{{ get_uuid_cmd }}"
|
2020-10-26 19:43:01 +01:00
|
|
|
changed_when: false
|
|
|
|
register: blkid
|
|
|
|
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Assert that the state changed but the filesystem still exists"
|
|
|
|
ansible.builtin.assert:
|
2020-10-26 19:43:01 +01:00
|
|
|
that:
|
|
|
|
- wipefs is changed
|
|
|
|
- blkid.stdout == blkid_ref.stdout
|
|
|
|
|
|
|
|
# Do it
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Remove filesystem"
|
|
|
|
community.general.filesystem:
|
2020-10-26 19:43:01 +01:00
|
|
|
dev: '{{ dev }}'
|
|
|
|
state: absent
|
|
|
|
register: wipefs
|
|
|
|
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Get filesystem UUID with 'blkid' (should be empty)"
|
2021-07-10 16:37:31 +02:00
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: "{{ get_uuid_cmd }}"
|
2020-10-26 19:43:01 +01:00
|
|
|
changed_when: false
|
|
|
|
failed_when: false
|
|
|
|
register: blkid
|
|
|
|
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Assert that the state changed and the device has no filesystem"
|
|
|
|
ansible.builtin.assert:
|
2020-10-26 19:43:01 +01:00
|
|
|
that:
|
|
|
|
- wipefs is changed
|
|
|
|
- blkid.stdout | length == 0
|
|
|
|
- blkid.rc == 2
|
|
|
|
|
|
|
|
# Do it again
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Remove filesystem (idempotency)"
|
|
|
|
community.general.filesystem:
|
2020-10-26 19:43:01 +01:00
|
|
|
dev: '{{ dev }}'
|
|
|
|
state: absent
|
|
|
|
register: wipefs
|
|
|
|
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Assert that the state did not change"
|
|
|
|
ansible.builtin.assert:
|
2020-10-26 19:43:01 +01:00
|
|
|
that:
|
|
|
|
- wipefs is not changed
|
|
|
|
|
|
|
|
# and again
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Remove filesystem (idempotency, check mode)"
|
|
|
|
community.general.filesystem:
|
2020-10-26 19:43:01 +01:00
|
|
|
dev: '{{ dev }}'
|
|
|
|
state: absent
|
|
|
|
register: wipefs
|
2023-02-15 22:55:23 +01:00
|
|
|
check_mode: true
|
2020-10-26 19:43:01 +01:00
|
|
|
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Assert that the state did not change"
|
|
|
|
ansible.builtin.assert:
|
2020-10-26 19:43:01 +01:00
|
|
|
that:
|
|
|
|
- wipefs is not changed
|
|
|
|
|
|
|
|
|
|
|
|
# By the way, test removal of a filesystem on unexistent device
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Remove filesystem (unexistent device)"
|
|
|
|
community.general.filesystem:
|
2020-10-26 19:43:01 +01:00
|
|
|
dev: '/dev/unexistent_device'
|
|
|
|
state: absent
|
|
|
|
register: wipefs
|
|
|
|
|
2021-05-18 06:46:45 +02:00
|
|
|
- name: "Assert that the state did not change"
|
|
|
|
ansible.builtin.assert:
|
2020-10-26 19:43:01 +01:00
|
|
|
that:
|
|
|
|
- wipefs is not changed
|