Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/filesystem/tasks/remove_fs.yml

raw
1 ---
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 # We assume 'create_fs' tests have passed.
7
8 - name: "Create filesystem"
9 community.general.filesystem:
10 dev: '{{ dev }}'
11 fstype: '{{ fstype }}'
12
13 - name: "Get filesystem UUID with 'blkid'"
14 ansible.builtin.shell:
15 cmd: "{{ get_uuid_cmd }}"
16 changed_when: false
17 register: blkid_ref
18
19 - name: "Assert that a filesystem exists on top of the device"
20 ansible.builtin.assert:
21 that:
22 - blkid_ref.stdout | length > 0
23
24
25 # Test check_mode first
26 - name: "Remove filesystem (check mode)"
27 community.general.filesystem:
28 dev: '{{ dev }}'
29 state: absent
30 register: wipefs
31 check_mode: true
32
33 - name: "Get filesystem UUID with 'blkid' (should remain the same)"
34 ansible.builtin.shell:
35 cmd: "{{ get_uuid_cmd }}"
36 changed_when: false
37 register: blkid
38
39 - name: "Assert that the state changed but the filesystem still exists"
40 ansible.builtin.assert:
41 that:
42 - wipefs is changed
43 - blkid.stdout == blkid_ref.stdout
44
45 # Do it
46 - name: "Remove filesystem"
47 community.general.filesystem:
48 dev: '{{ dev }}'
49 state: absent
50 register: wipefs
51
52 - name: "Get filesystem UUID with 'blkid' (should be empty)"
53 ansible.builtin.shell:
54 cmd: "{{ get_uuid_cmd }}"
55 changed_when: false
56 failed_when: false
57 register: blkid
58
59 - name: "Assert that the state changed and the device has no filesystem"
60 ansible.builtin.assert:
61 that:
62 - wipefs is changed
63 - blkid.stdout | length == 0
64 - blkid.rc == 2
65
66 # Do it again
67 - name: "Remove filesystem (idempotency)"
68 community.general.filesystem:
69 dev: '{{ dev }}'
70 state: absent
71 register: wipefs
72
73 - name: "Assert that the state did not change"
74 ansible.builtin.assert:
75 that:
76 - wipefs is not changed
77
78 # and again
79 - name: "Remove filesystem (idempotency, check mode)"
80 community.general.filesystem:
81 dev: '{{ dev }}'
82 state: absent
83 register: wipefs
84 check_mode: true
85
86 - name: "Assert that the state did not change"
87 ansible.builtin.assert:
88 that:
89 - wipefs is not changed
90
91
92 # By the way, test removal of a filesystem on unexistent device
93 - name: "Remove filesystem (unexistent device)"
94 community.general.filesystem:
95 dev: '/dev/unexistent_device'
96 state: absent
97 register: wipefs
98
99 - name: "Assert that the state did not change"
100 ansible.builtin.assert:
101 that:
102 - wipefs is not changed