2022-05-31-00

This commit is contained in:
Hideki Saito 2022-05-31 09:17:39 +09:00
parent 18c847a8a0
commit 20b74cadd3
2 changed files with 412 additions and 408 deletions

View file

@ -277,8 +277,6 @@ stages:
dependsOn: dependsOn:
- Remote_2_9 - Remote_2_9
- Docker_2_9 - Docker_2_9
- Remote_2_10
- Docker_2_10
- Remote_2_11 - Remote_2_11
- Docker_2_11 - Docker_2_11
- Remote_2_12 - Remote_2_12

View file

@ -1,408 +1,414 @@
- name: Create the mount point #- name: Create the mount point
file: # file:
state: directory # state: directory
path: '{{ output_dir }}/mount_dest' # path: '{{ output_dir }}/mount_dest'
#
- name: Create a directory to bind mount #- name: Create a directory to bind mount
file: # file:
state: directory # state: directory
path: '{{ output_dir }}/mount_source' # path: '{{ output_dir }}/mount_source'
#
- name: Put something in the directory so we see that it worked #- name: Put something in the directory so we see that it worked
copy: # copy:
content: 'Testing # content: 'Testing
#
' # '
dest: '{{ output_dir }}/mount_source/test_file' # dest: '{{ output_dir }}/mount_source/test_file'
register: orig_info # register: orig_info
#
- name: Bind mount a filesystem (Linux) #- name: Bind mount a filesystem (Linux)
mount: # mount:
src: '{{ output_dir }}/mount_source' # src: '{{ output_dir }}/mount_source'
name: '{{ output_dir }}/mount_dest' # name: '{{ output_dir }}/mount_dest'
state: mounted # state: mounted
fstype: None # fstype: None
opts: bind # opts: bind
when: ansible_system == 'Linux' # when: ansible_system == 'Linux'
register: bind_result_linux # register: bind_result_linux
#
- name: Bind mount a filesystem (FreeBSD) #- name: Bind mount a filesystem (FreeBSD)
mount: # mount:
src: '{{ output_dir }}/mount_source' # src: '{{ output_dir }}/mount_source'
name: '{{ output_dir }}/mount_dest' # name: '{{ output_dir }}/mount_dest'
state: mounted # state: mounted
fstype: nullfs # fstype: nullfs
when: ansible_system == 'FreeBSD' # when: ansible_system == 'FreeBSD'
register: bind_result_freebsd # register: bind_result_freebsd
#
- name: get checksum for bind mounted file #- name: get checksum for bind mounted file
stat: # stat:
path: '{{ output_dir }}/mount_dest/test_file' # path: '{{ output_dir }}/mount_dest/test_file'
when: ansible_system in ('FreeBSD', 'Linux') # when: ansible_system in ('FreeBSD', 'Linux')
register: dest_stat # register: dest_stat
#
- name: assert the bind mount was successful #- name: assert the bind mount was successful
assert: # assert:
that: # that:
- (ansible_system == 'Linux' and bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and bind_result_freebsd['changed']) # - (ansible_system == 'Linux' and bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and bind_result_freebsd['changed'])
- dest_stat['stat']['exists'] # - dest_stat['stat']['exists']
- orig_info['checksum'] == dest_stat['stat']['checksum'] # - orig_info['checksum'] == dest_stat['stat']['checksum']
when: ansible_system in ('FreeBSD', 'Linux') # when: ansible_system in ('FreeBSD', 'Linux')
#
- name: Bind mount a filesystem (Linux) #- name: Bind mount a filesystem (Linux)
mount: # mount:
src: '{{ output_dir }}/mount_source' # src: '{{ output_dir }}/mount_source'
name: '{{ output_dir }}/mount_dest' # name: '{{ output_dir }}/mount_dest'
state: mounted # state: mounted
fstype: None # fstype: None
opts: bind # opts: bind
when: ansible_system == 'Linux' # when: ansible_system == 'Linux'
register: bind_result_linux # register: bind_result_linux
#
- name: Bind mount a filesystem (FreeBSD) #- name: Bind mount a filesystem (FreeBSD)
mount: # mount:
src: '{{ output_dir }}/mount_source' # src: '{{ output_dir }}/mount_source'
name: '{{ output_dir }}/mount_dest' # name: '{{ output_dir }}/mount_dest'
state: mounted # state: mounted
fstype: nullfs # fstype: nullfs
when: ansible_system == 'FreeBSD' # when: ansible_system == 'FreeBSD'
register: bind_result_freebsd # register: bind_result_freebsd
#
- name: Make sure we didn't mount a second time #- name: Make sure we didn't mount a second time
assert: # assert:
that: # that:
- (ansible_system == 'Linux' and not bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and not bind_result_freebsd['changed']) # - (ansible_system == 'Linux' and not bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and not bind_result_freebsd['changed'])
when: ansible_system in ('FreeBSD', 'Linux') # when: ansible_system in ('FreeBSD', 'Linux')
#
- name: Remount filesystem with different opts (Linux) #- name: Remount filesystem with different opts (Linux)
mount: # mount:
src: '{{ output_dir }}/mount_source' # src: '{{ output_dir }}/mount_source'
name: '{{ output_dir }}/mount_dest' # name: '{{ output_dir }}/mount_dest'
state: mounted # state: mounted
fstype: None # fstype: None
opts: bind,ro # opts: bind,ro
when: ansible_system == 'Linux' # when: ansible_system == 'Linux'
register: bind_result_linux # register: bind_result_linux
#
- name: Remount filesystem with different opts (FreeBSD) #- name: Remount filesystem with different opts (FreeBSD)
mount: # mount:
src: '{{ output_dir }}/mount_source' # src: '{{ output_dir }}/mount_source'
name: '{{ output_dir }}/mount_dest' # name: '{{ output_dir }}/mount_dest'
state: mounted # state: mounted
fstype: nullfs # fstype: nullfs
opts: ro # opts: ro
when: ansible_system == 'FreeBSD' # when: ansible_system == 'FreeBSD'
register: bind_result_freebsd # register: bind_result_freebsd
#
- name: Get mount options #- name: Get mount options
shell: mount | grep mount_dest | grep -E -w '(ro|read-only)' | wc -l # shell: mount | grep mount_dest | grep -E -w '(ro|read-only)' | wc -l
register: remount_options # register: remount_options
#
- name: Make sure the filesystem now has the new opts #- name: Make sure the filesystem now has the new opts
assert: # assert:
that: # that:
- (ansible_system == 'Linux' and bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and bind_result_freebsd['changed']) # - (ansible_system == 'Linux' and bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and bind_result_freebsd['changed'])
- '''1'' in remount_options.stdout' # - '''1'' in remount_options.stdout'
- 1 == remount_options.stdout_lines | length # - 1 == remount_options.stdout_lines | length
when: ansible_system in ('FreeBSD', 'Linux') # when: ansible_system in ('FreeBSD', 'Linux')
#
- name: Unmount the bind mount #- name: Unmount the bind mount
mount: # mount:
name: '{{ output_dir }}/mount_dest' # name: '{{ output_dir }}/mount_dest'
state: absent # state: absent
when: ansible_system in ('Linux', 'FreeBSD') # when: ansible_system in ('Linux', 'FreeBSD')
register: unmount_result # register: unmount_result
#
- name: Make sure the file no longer exists in dest #- name: Make sure the file no longer exists in dest
stat: # stat:
path: '{{ output_dir }}/mount_dest/test_file' # path: '{{ output_dir }}/mount_dest/test_file'
when: ansible_system in ('FreeBSD', 'Linux') # when: ansible_system in ('FreeBSD', 'Linux')
register: dest_stat # register: dest_stat
#
- name: Check that we unmounted #- name: Check that we unmounted
assert: # assert:
that: # that:
- unmount_result['changed'] # - unmount_result['changed']
- not dest_stat['stat']['exists'] # - not dest_stat['stat']['exists']
when: ansible_system in ('FreeBSD', 'Linux') # when: ansible_system in ('FreeBSD', 'Linux')
#
- name: Block to test remounted option #- name: Block to test remounted option
block: # block:
- name: Create fstab record for the first swap file # - name: Create fstab record for the first swap file
mount: # mount:
name: none # name: none
src: /tmp/swap1 # src: /tmp/swap1
opts: sw # opts: sw
fstype: swap # fstype: swap
state: present # state: present
register: swap1_created # register: swap1_created
#
- 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:
name: none # name: none
src: /tmp/swap1 # src: /tmp/swap1
opts: sw # opts: sw
fstype: swap # fstype: swap
state: present # state: present
register: swap1_created_again # register: swap1_created_again
#
- 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']
#
- name: Create fstab record for the second swap file # - name: Create fstab record for the second swap file
mount: # mount:
name: none # name: none
src: /tmp/swap2 # src: /tmp/swap2
opts: sw # opts: sw
fstype: swap # fstype: swap
state: present # state: present
register: swap2_created # register: swap2_created
#
- 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:
name: none # name: none
src: /tmp/swap1 # src: /tmp/swap1
opts: sw # opts: sw
fstype: swap # fstype: swap
state: present # state: present
register: swap2_created_again # register: swap2_created_again
#
- 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']
#
- name: Remove the fstab record for the first swap file # - name: Remove the fstab record for the first swap file
mount: # mount:
name: none # name: none
src: /tmp/swap1 # src: /tmp/swap1
state: absent # state: absent
register: swap1_removed # register: swap1_removed
#
- 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:
name: none # name: none
src: /tmp/swap1 # src: /tmp/swap1
state: absent # state: absent
register: swap1_removed_again # register: swap1_removed_again
#
- 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']
#
- name: Remove the fstab record for the second swap file # - name: Remove the fstab record for the second swap file
mount: # mount:
name: none # name: none
src: /tmp/swap2 # src: /tmp/swap2
state: absent # state: absent
register: swap2_removed # register: swap2_removed
#
- 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:
name: none # name: none
src: /tmp/swap2 # src: /tmp/swap2
state: absent # state: absent
register: swap2_removed_again # register: swap2_removed_again
#
- 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']
#
- name: Create fstab record with missing last two fields # - name: Create fstab record with missing last two fields
copy: # copy:
dest: /etc/fstab # dest: /etc/fstab
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
#
' # '
#
- 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:
src: //nas/photo # src: //nas/photo
path: /home/jik/pictures # path: /home/jik/pictures
fstype: cifs # fstype: cifs
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
#
- 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
#
- 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:
that: # that:
- 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
#
# - name: Create empty file
# community.general.filesize:
# path: /tmp/myfs.img
# size: 20M
#
# - name: Format FS
# community.general.filesystem:
# fstype: ext3
# dev: /tmp/myfs.img
#
# - name: Mount the FS for the first time
# mount:
# path: /tmp/myfs
# src: /tmp/myfs.img
# fstype: ext2
# state: mounted
#
# - name: Get the last write time
# shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-'
# register: last_write_time
#
# - name: Wait 2 second
# pause:
# seconds: 2
#
# - name: Test if the FS is remounted
# mount:
# path: /tmp/myfs
# state: remounted
#
# - name: Get again the last write time
# shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-'
# register: last_write_time2
#
# - name: Fail if they are the same
# fail:
# msg: Filesytem was not remounted, testing of the module failed!
# when: last_write is defined and last_write_time2 is defined and last_write_time.stdout == last_write_time2.stdout
#
# - name: Remount filesystem with different opts using remounted option (Linux only)
# mount:
# path: /tmp/myfs
# state: remounted
# opts: rw,noexec
#
# - name: Get remounted options (Linux only)
# shell: mount | grep myfs | grep -E -w 'noexec' | wc -l
# register: remounted_options
#
# - name: Make sure the filesystem now has the new opts after using remounted (Linux only)
# assert:
# that:
# - "'1' in remounted_options.stdout"
# - "1 == remounted_options.stdout_lines | length"
#
# - name: Mount the FS again to test backup
# mount:
# path: /tmp/myfs
# src: /tmp/myfs.img
# fstype: ext2
# state: mounted
# backup: yes
# register: mount_backup_out
#
# - name: ensure backup_file in returned output
# assert:
# that:
# - "'backup_file' in mount_backup_out"
#
# always:
# - name: Umount the test FS
# mount:
# path: /tmp/myfs
# src: /tmp/myfs.img
# opts: loop
# state: absent
#
# - name: Remove the test FS
# file:
# path: '{{ item }}'
# state: absent
# loop:
# - /tmp/myfs.img
# - /tmp/myfs
# when: ansible_system in ('Linux')
#
#- name: Block to test boot option for Linux
# block:
# - name: Create empty file
# community.general.filesize:
# path: /tmp/myfs.img
# size: 20M
#
# - name: Format FS
# community.general.filesystem:
# fstype: ext3
# dev: /tmp/myfs.img
#
# - name: Mount the FS with noauto option
# mount:
# path: /tmp/myfs
# src: /tmp/myfs.img
# fstype: ext3
# state: mounted
# boot: no
# opts: rw,user,async
# register: mount_info
#
# - name: assert the mount without noauto was successful
# assert:
# that:
# - mount_info['opts'] == 'rw,user,async,noauto'
#
# - name: Unmount FS
# mount:
# path: /tmp/myfs
# state: absent
#
# - name: Remove the test FS
# file:
# path: '{{ item }}'
# state: absent
# loop:
# - /tmp/myfs.img
# - /tmp/myfs
# when: ansible_system in ('Linux')
#
#- name: Block to test missing newline at the EOF of fstab
# block:
# - name: Create empty file
# community.general.filesize:
# path: /tmp/myfs1.img
# size: 20M
# - name: Format FS
# community.general.filesystem:
# fstype: ext3
# dev: /tmp/myfs1.img
# - name: Create custom fstab file without newline
# copy:
# content: '#TEST COMMENT WITHOUT NEWLINE'
# dest: /tmp/test_fstab
# - name: Mount the FS using the custom fstab
# mount:
# path: /tmp/myfs1
# src: /tmp/myfs1.img
# fstype: ext3
# state: mounted
# opts: defaults
# fstab: /tmp/test_fstab
# - name: Unmount the mount point in the custom fstab
# mount:
# path: /tmp/myfs1
# state: absent
# fstab: /tmp/test_fstab
# - name: Remove the test FS and the custom fstab
# file:
# path: '{{ item }}'
# state: absent
# loop:
# - /tmp/myfs1.img
# - /tmp/myfs1
# - /tmp/test_fstab
# when: ansible_system in ('Linux')
- name: Create empty file - name: Create empty file
community.general.filesize: community.general.filesize:
path: /tmp/myfs.img path: /tmp/myfs.img
size: 20M size: 20M
- name: Format FS
community.general.filesystem:
fstype: ext3
dev: /tmp/myfs.img
- name: Mount the FS for the first time
mount:
path: /tmp/myfs
src: /tmp/myfs.img
fstype: ext2
state: mounted
- name: Get the last write time
shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-'
register: last_write_time
- name: Wait 2 second
pause:
seconds: 2
- name: Test if the FS is remounted
mount:
path: /tmp/myfs
state: remounted
- name: Get again the last write time
shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-'
register: last_write_time2
- name: Fail if they are the same
fail:
msg: Filesytem was not remounted, testing of the module failed!
when: last_write is defined and last_write_time2 is defined and last_write_time.stdout == last_write_time2.stdout
- name: Remount filesystem with different opts using remounted option (Linux only)
mount:
path: /tmp/myfs
state: remounted
opts: rw,noexec
- name: Get remounted options (Linux only)
shell: mount | grep myfs | grep -E -w 'noexec' | wc -l
register: remounted_options
- name: Make sure the filesystem now has the new opts after using remounted (Linux only)
assert:
that:
- "'1' in remounted_options.stdout"
- "1 == remounted_options.stdout_lines | length"
- name: Mount the FS again to test backup
mount:
path: /tmp/myfs
src: /tmp/myfs.img
fstype: ext2
state: mounted
backup: yes
register: mount_backup_out
- name: ensure backup_file in returned output
assert:
that:
- "'backup_file' in mount_backup_out"
always:
- name: Umount the test FS
mount:
path: /tmp/myfs
src: /tmp/myfs.img
opts: loop
state: absent
- name: Remove the test FS
file:
path: '{{ item }}'
state: absent
loop:
- /tmp/myfs.img
- /tmp/myfs
when: ansible_system in ('Linux')
- name: Block to test boot option for Linux
block:
- name: Create empty file
community.general.filesize:
path: /tmp/myfs.img
size: 20M
- name: Format FS
community.general.filesystem:
fstype: ext3
dev: /tmp/myfs.img
- name: Mount the FS with noauto option
mount:
path: /tmp/myfs
src: /tmp/myfs.img
fstype: ext3
state: mounted
boot: no
opts: rw,user,async
register: mount_info
- name: assert the mount without noauto was successful
assert:
that:
- mount_info['opts'] == 'rw,user,async,noauto'
- name: Unmount FS
mount:
path: /tmp/myfs
state: absent
- name: Remove the test FS
file:
path: '{{ item }}'
state: absent
loop:
- /tmp/myfs.img
- /tmp/myfs
when: ansible_system in ('Linux')
- name: Block to test missing newline at the EOF of fstab
block:
- name: Create empty file
community.general.filesize:
path: /tmp/myfs1.img
size: 20M
- name: Format FS
community.general.filesystem:
fstype: ext3
dev: /tmp/myfs1.img
- name: Create custom fstab file without newline
copy:
content: '#TEST COMMENT WITHOUT NEWLINE'
dest: /tmp/test_fstab
- name: Mount the FS using the custom fstab
mount:
path: /tmp/myfs1
src: /tmp/myfs1.img
fstype: ext3
state: mounted
opts: defaults
fstab: /tmp/test_fstab
- name: Unmount the mount point in the custom fstab
mount:
path: /tmp/myfs1
state: absent
fstab: /tmp/test_fstab
- name: Remove the test FS and the custom fstab
file:
path: '{{ item }}'
state: absent
loop:
- /tmp/myfs1.img
- /tmp/myfs1
- /tmp/test_fstab
when: ansible_system in ('Linux') when: ansible_system in ('Linux')