EFI: Take into consideration the new GPT layout.
[ta/infra-ansible.git] / roles / partfs_rootdisk / tasks / root_disk_volume_groups.yml
1 ---
2
3 # Copyright 2019 Nokia
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 - name: check if this is partfs_rootdisk re-run
18   stat:
19     path: /etc/partfs_rootdisk_created
20   ignore_errors: yes
21   register: rerun_case
22
23 - name: Create /tmp/<node_name>localstorage.json file
24   template:
25     src: "localstorage.j2"
26     dest: "/tmp/{{inventory_hostname}}_localstorage.json"
27     owner: "root"
28     mode: "0644"
29   delegate_to: "{{installation_controller}}"
30
31 - name: Load variables from the json file
32   include_vars: "/tmp/{{inventory_hostname}}_localstorage.json"
33
34 - name: Remove /tmp/<node_name>localstorage.json file
35   file:
36     path: "/tmp/{{inventory_hostname}}_localstorage.json"
37     state: "absent"
38   delegate_to: "{{installation_controller}}"
39
40 - name: Create Partition for LVMs
41   parted:
42     device: "{{root_disk}}"
43     number: "{{lvm_part_number}}"
44     unit: "GB"
45     label: "{{root_disk_info.disk.table}}"
46     flags: [ lvm ]
47     state: present
48     part_start: "{{lvm_part_start}}GB"
49     part_end: "{{lvm_part_end}}GB"
50   when:
51     - create_disk_part | bool
52
53 - set_fact:
54     vg_disk: "{% if root_disk == default_rootdisk_device %}{{root_disk}}{{lvm_part_number}}{% else %}{{root_disk}}-part{{lvm_part_number}}{% endif %}"
55
56 - debug:
57     msg: "{{vg_disk}}"
58
59 - name: Create PV VG
60   lvg:
61     vg: VG
62     pvs: "{{vg_disk}}"
63
64 - name: Delete old LVMs if not mounted already
65   script: "{{role_path}}/scripts/old_vol_rm.sh"
66   args:
67     creates: /etc/partfs_rootdisk_created
68
69 - name: Creating LVM
70   lvol:
71     vg: VG
72     lv: "{{vol['lvm_name']}}"
73     size: "{{vol['lvm_size']}}"
74   with_items: "{{device_mapping|sort(attribute='mount_point')}}"
75   loop_control:
76     loop_var: vol
77   when:
78     - rerun_case.stat.exists is undefined or rerun_case.stat.exists == false
79
80 - name: Create XFS filesystem on LVM
81   filesystem:
82     fstype: xfs
83     dev: "/dev/mapper/VG-{{vol['lvm_name']}}"
84   with_items: "{{device_mapping|sort(attribute='mount_point')}}"
85   loop_control:
86     loop_var: vol
87
88 - name: Create fstab entry.
89   mount:
90     path: "{{vol['mount_point']}}"
91     src: "/dev/mapper/VG-{{vol['lvm_name']}}"
92     fstype: xfs
93     opts: "{{vol['mount_opts']}}"
94     state: present
95   with_items: "{{device_mapping|sort(attribute='mount_point')}}"
96   loop_control:
97     loop_var: vol
98
99 # Run below script to do the following tasks
100 #-  Stop existing services
101 #-  Move the current files to a tmp location
102 #-  mount LVM on mount dir
103 #-  restore old files
104 #-  Start old services
105 #- It creates logs in the target node at /tmp/vol_mgmt_logfile
106 - name: Running a script to remount volume on target dir
107   script: "{{role_path}}/scripts/vol_mgmt.sh {{vol['mount_point']}} /dev/mapper/VG-{{vol['lvm_name']}}"
108   with_items: "{{device_mapping|sort(attribute='mount_point')}}"
109   loop_control:
110     loop_var: vol
111   args:
112     creates: /etc/partfs_rootdisk_created
113
114 - name: Check if Root partition can grow
115   shell: "growpart --dry-run $(readlink -f {{root_disk}}) 1"
116   register: rootpart
117   ignore_errors: yes
118   args:
119     creates: /etc/partfs_rootdisk_created
120
121 - name: Grow Root partition
122   shell: "growpart $(readlink -f {{root_disk}}) 1"
123   when: rootpart.rc == 0
124   args:
125     creates: /etc/partfs_rootdisk_created
126
127 - name: Grow xfs filesystem on Root partition
128   command: "xfs_growfs /"
129   args:
130     creates: /etc/partfs_rootdisk_created