mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-01-12 15:45:20 +01:00
Clean, use blocks in main.yml
This commit is contained in:
parent
606e3cfe07
commit
dd7d29495d
1 changed files with 5 additions and 31 deletions
|
|
@ -136,7 +136,6 @@
|
||||||
fstype: swap
|
fstype: swap
|
||||||
state: present
|
state: present
|
||||||
register: swap1_created
|
register: swap1_created
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Try to create fstab record for the first swap file again
|
- name: Try to create fstab record for the first swap file again
|
||||||
mount:
|
mount:
|
||||||
|
|
@ -146,14 +145,12 @@
|
||||||
fstype: swap
|
fstype: swap
|
||||||
state: present
|
state: present
|
||||||
register: swap1_created_again
|
register: swap1_created_again
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Check that we created the swap1 record
|
- name: Check that we created the swap1 record
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- swap1_created['changed']
|
- swap1_created['changed']
|
||||||
- not swap1_created_again['changed']
|
- not swap1_created_again['changed']
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Create fstab record for the second swap file
|
- name: Create fstab record for the second swap file
|
||||||
mount:
|
mount:
|
||||||
|
|
@ -163,7 +160,6 @@
|
||||||
fstype: swap
|
fstype: swap
|
||||||
state: present
|
state: present
|
||||||
register: swap2_created
|
register: swap2_created
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Try to create fstab record for the second swap file again
|
- name: Try to create fstab record for the second swap file again
|
||||||
mount:
|
mount:
|
||||||
|
|
@ -173,14 +169,12 @@
|
||||||
fstype: swap
|
fstype: swap
|
||||||
state: present
|
state: present
|
||||||
register: swap2_created_again
|
register: swap2_created_again
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Check that we created the swap2 record
|
- name: Check that we created the swap2 record
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- swap2_created['changed']
|
- swap2_created['changed']
|
||||||
- not swap2_created_again['changed']
|
- not swap2_created_again['changed']
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Remove the fstab record for the first swap file
|
- name: Remove the fstab record for the first swap file
|
||||||
mount:
|
mount:
|
||||||
|
|
@ -188,7 +182,6 @@
|
||||||
src: /tmp/swap1
|
src: /tmp/swap1
|
||||||
state: absent
|
state: absent
|
||||||
register: swap1_removed
|
register: swap1_removed
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Try to remove the fstab record for the first swap file again
|
- name: Try to remove the fstab record for the first swap file again
|
||||||
mount:
|
mount:
|
||||||
|
|
@ -196,14 +189,12 @@
|
||||||
src: /tmp/swap1
|
src: /tmp/swap1
|
||||||
state: absent
|
state: absent
|
||||||
register: swap1_removed_again
|
register: swap1_removed_again
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Check that we removed the swap1 record
|
- name: Check that we removed the swap1 record
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- swap1_removed['changed']
|
- swap1_removed['changed']
|
||||||
- not swap1_removed_again['changed']
|
- not swap1_removed_again['changed']
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Remove the fstab record for the second swap file
|
- name: Remove the fstab record for the second swap file
|
||||||
mount:
|
mount:
|
||||||
|
|
@ -211,7 +202,6 @@
|
||||||
src: /tmp/swap2
|
src: /tmp/swap2
|
||||||
state: absent
|
state: absent
|
||||||
register: swap2_removed
|
register: swap2_removed
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Try to remove the fstab record for the second swap file again
|
- name: Try to remove the fstab record for the second swap file again
|
||||||
mount:
|
mount:
|
||||||
|
|
@ -219,14 +209,12 @@
|
||||||
src: /tmp/swap2
|
src: /tmp/swap2
|
||||||
state: absent
|
state: absent
|
||||||
register: swap2_removed_again
|
register: swap2_removed_again
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Check that we removed the swap2 record
|
- name: Check that we removed the swap2 record
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- swap2_removed['changed']
|
- swap2_removed['changed']
|
||||||
- not swap2_removed_again['changed']
|
- not swap2_removed_again['changed']
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Create fstab record with missing last two fields
|
- name: Create fstab record with missing last two fields
|
||||||
copy:
|
copy:
|
||||||
|
|
@ -234,7 +222,6 @@
|
||||||
content: '//nas/photo /home/jik/pictures cifs defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev
|
content: '//nas/photo /home/jik/pictures cifs defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev
|
||||||
|
|
||||||
'
|
'
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Try to change the fstab record with the missing last two fields
|
- name: Try to change the fstab record with the missing last two fields
|
||||||
mount:
|
mount:
|
||||||
|
|
@ -244,12 +231,10 @@
|
||||||
opts: defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev,x-systemd.mount-timeout=0
|
opts: defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev,x-systemd.mount-timeout=0
|
||||||
state: present
|
state: present
|
||||||
register: optional_fields_update
|
register: optional_fields_update
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Get the content of the fstab file
|
- name: Get the content of the fstab file
|
||||||
shell: cat /etc/fstab
|
shell: cat /etc/fstab
|
||||||
register: optional_fields_content
|
register: optional_fields_content
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Check if the line containing the missing last two fields was changed
|
- name: Check if the line containing the missing last two fields was changed
|
||||||
assert:
|
assert:
|
||||||
|
|
@ -257,14 +242,14 @@
|
||||||
- optional_fields_update['changed']
|
- optional_fields_update['changed']
|
||||||
- ''' 0 0'' in optional_fields_content.stdout'
|
- ''' 0 0'' in optional_fields_content.stdout'
|
||||||
- 1 == optional_fields_content.stdout_lines | length
|
- 1 == optional_fields_content.stdout_lines | length
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Create empty file
|
- name: Create empty file
|
||||||
command: dd if=/dev/zero of=/tmp/myfs.img bs=1048576 count=20
|
community.general.filesize:
|
||||||
|
path: /tmp/myfs.img
|
||||||
|
size: 20M
|
||||||
|
|
||||||
- name: Format FS
|
- name: Format FS
|
||||||
when: ansible_system in ('Linux')
|
community.general.filesystem:
|
||||||
community.general.system.filesystem:
|
|
||||||
fstype: ext3
|
fstype: ext3
|
||||||
dev: /tmp/myfs.img
|
dev: /tmp/myfs.img
|
||||||
|
|
||||||
|
|
@ -274,28 +259,23 @@
|
||||||
src: /tmp/myfs.img
|
src: /tmp/myfs.img
|
||||||
fstype: ext2
|
fstype: ext2
|
||||||
state: mounted
|
state: mounted
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Get the last write time
|
- name: Get the last write time
|
||||||
shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-'
|
shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-'
|
||||||
register: last_write_time
|
register: last_write_time
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Wait 2 second
|
- name: Wait 2 second
|
||||||
pause:
|
pause:
|
||||||
seconds: 2
|
seconds: 2
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Test if the FS is remounted
|
- name: Test if the FS is remounted
|
||||||
mount:
|
mount:
|
||||||
path: /tmp/myfs
|
path: /tmp/myfs
|
||||||
state: remounted
|
state: remounted
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Get again the last write time
|
- name: Get again the last write time
|
||||||
shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-'
|
shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-'
|
||||||
register: last_write_time2
|
register: last_write_time2
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Fail if they are the same
|
- name: Fail if they are the same
|
||||||
fail:
|
fail:
|
||||||
|
|
@ -307,19 +287,16 @@
|
||||||
path: /tmp/myfs
|
path: /tmp/myfs
|
||||||
state: remounted
|
state: remounted
|
||||||
opts: rw,noexec
|
opts: rw,noexec
|
||||||
when: ansible_system == 'Linux'
|
|
||||||
|
|
||||||
- name: Get remounted options (Linux only)
|
- name: Get remounted options (Linux only)
|
||||||
shell: mount | grep myfs | grep -E -w 'noexec' | wc -l
|
shell: mount | grep myfs | grep -E -w 'noexec' | wc -l
|
||||||
register: remounted_options
|
register: remounted_options
|
||||||
when: ansible_system == 'Linux'
|
|
||||||
|
|
||||||
- name: Make sure the filesystem now has the new opts after using remounted (Linux only)
|
- name: Make sure the filesystem now has the new opts after using remounted (Linux only)
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "'1' in remounted_options.stdout"
|
- "'1' in remounted_options.stdout"
|
||||||
- "1 == remounted_options.stdout_lines | length"
|
- "1 == remounted_options.stdout_lines | length"
|
||||||
when: ansible_system == 'Linux'
|
|
||||||
|
|
||||||
- name: Mount the FS again to test backup
|
- name: Mount the FS again to test backup
|
||||||
mount:
|
mount:
|
||||||
|
|
@ -329,13 +306,11 @@
|
||||||
state: mounted
|
state: mounted
|
||||||
backup: yes
|
backup: yes
|
||||||
register: mount_backup_out
|
register: mount_backup_out
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: ensure backup_file in returned output
|
- name: ensure backup_file in returned output
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "'backup_file' in mount_backup_out"
|
- "'backup_file' in mount_backup_out"
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Umount the test FS
|
- name: Umount the test FS
|
||||||
|
|
@ -344,7 +319,6 @@
|
||||||
src: /tmp/myfs.img
|
src: /tmp/myfs.img
|
||||||
opts: loop
|
opts: loop
|
||||||
state: absent
|
state: absent
|
||||||
when: ansible_system in ('Linux')
|
|
||||||
|
|
||||||
- name: Remove the test FS
|
- name: Remove the test FS
|
||||||
file:
|
file:
|
||||||
|
|
@ -353,7 +327,7 @@
|
||||||
loop:
|
loop:
|
||||||
- /tmp/myfs.img
|
- /tmp/myfs.img
|
||||||
- /tmp/myfs
|
- /tmp/myfs
|
||||||
when: ansible_system in ('Linux')
|
when: ansible_system in ('Linux')
|
||||||
|
|
||||||
- name: Block to test boot option for Linux
|
- name: Block to test boot option for Linux
|
||||||
block:
|
block:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue