diff options
Diffstat (limited to 'roles/ubuntu-ws/tasks/fs.yaml')
-rw-r--r-- | roles/ubuntu-ws/tasks/fs.yaml | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/roles/ubuntu-ws/tasks/fs.yaml b/roles/ubuntu-ws/tasks/fs.yaml new file mode 100644 index 00000000..07358b99 --- /dev/null +++ b/roles/ubuntu-ws/tasks/fs.yaml @@ -0,0 +1,99 @@ +--- +- name: resize root logical volume + lvol: + vg: "{{ inventory_hostname }}" + lv: root + size: "{{ ubuntu_ws_root_fs_size }}" + +- name: create/resize root filesystem + filesystem: + fstype: ext4 + dev: "/dev/mapper/{{ inventory_hostname | replace('-', '--') }}-root" + resizefs: yes + +- name: create/resize home logical volume + lvol: + vg: "{{ inventory_hostname }}" + lv: home + size: "{{ ubuntu_ws_home_fs_size }}" + +- name: create/resize home filesystem + filesystem: + fstype: ext4 + dev: "/dev/mapper/{{ inventory_hostname | replace('-', '--') }}-home" + resizefs: yes + +- name: check if home is already mounted + command: "mountpoint -q /home" + register: home_mounted + check_mode: False + failed_when: False + changed_when: False + +- name: check if there are files in /home + find: + paths: /home + file_type: any + register: home_files + +- name: move existing files to new filesystem + when: home_mounted.rc == 1 and home_files.matched != 0 + block: + - name: create temporary mountpoint (1/2) + tempfile: + state: directory + suffix: mnt-home + register: mnt_home_temp + + - name: create temporary mountpoint (1/2) + file: + state: directory + path: "{{ mnt_home_temp.path }}/mnt" + + - name: temporarly mount new home filesystem + mount: + path: "{{ mnt_home_temp.path }}/mnt" + src: "/dev/mapper/{{ inventory_hostname | replace('-', '--') }}-home" + state: mounted + fstype: ext4 + fstab: "{{ mnt_home_temp.path }}/fstab" + + - name: check if target fs is empty + find: + paths: "{{ mnt_home_temp.path }}/mnt" + file_type: any + register: home_files_target + failed_when: home_files_target.matched > 1 or (home_files_target.matched == 1 and home_files_target.files[0].path != mnt_home_temp.path + "/mnt/lost+found") + + - name: copy all files from old /home to new filesystem + command: "find -maxdepth 1 -exec cp -a {} {{ mnt_home_temp.path }}/mnt/ \\;" + args: + chdir: /home + + - name: remove all files from old /home + file: + path: /home + state: absent + + - name: recreate /home mountpoint + file: + path: /home + state: directory + + - name: umount temporarly mounted home filesystem + mount: + path: "{{ mnt_home_temp.path }}/mnt" + state: unmounted + + - name: remove temporary mountpoint + file: + state: absent + path: "{{ mnt_home_temp.path }}" + +- name: mount home filesystem + mount: + path: /home + src: "/dev/mapper/{{ inventory_hostname | replace('-', '--') }}-home" + state: mounted + fstype: ext4 + opts: nodev |