summaryrefslogtreecommitdiff
path: root/roles/ubuntu-ws/tasks/fs.yml
blob: 7a227594b043fd6e918e7670bb3b00c94a46529a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
- name: resize root logical volume
  lvol:
    vg: "{{ hostvars[inventory_hostname].host_name }}"
    lv: root
    size: "{{ ubuntu_ws_root_fs_size }}"

- name: create/resize root filesystem
  filesystem:
    fstype: ext4
    dev: "/dev/mapper/{{ hostvars[inventory_hostname].host_name | replace('-', '--') }}-root"
    resizefs: yes

- name: create/resize home logical volume
  lvol:
    vg: "{{ hostvars[inventory_hostname].host_name }}"
    lv: home
    size: "{{ ubuntu_ws_home_fs_size }}"

- name: create/resize home filesystem
  filesystem:
    fstype: ext4
    dev: "/dev/mapper/{{ hostvars[inventory_hostname].host_name | 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/{{ hostvars[inventory_hostname].host_name | 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/{{ hostvars[inventory_hostname].host_name | replace('-', '--') }}-home"
    state: mounted
    fstype: ext4
    opts: nodev