Initial commit
[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: "{{phy_disk_part_number}}"
44     flags: [ lvm ]
45     state: present
46     part_start: "{{part_start}}"
47     part_end: "{{part_end}}"
48   when:
49     - create_disk_part | bool
50     - rootdisk_vg_percentage != all_disk_size_for_volume_group_vg
51
52 - name: Create Partition for LVMs
53   parted:
54     device: "{{root_disk}}"
55     number: "{{phy_disk_part_number}}"
56     flags: [ lvm ]
57     state: present
58     part_start: "{{part_start}}"
59   when:
60     - create_disk_part | bool
61     - rootdisk_vg_percentage == all_disk_size_for_volume_group_vg
62
63 - set_fact:
64     vg_disk: "{% if root_disk == default_rootdisk_device %}{{root_disk}}{{phy_disk_part_number}}{% else %}{{root_disk}}-part{{phy_disk_part_number}}{% endif %}"
65
66 - debug:
67     msg: "{{vg_disk}}"
68
69 - name: Create PV VG
70   lvg:
71     vg: VG
72     pvs: "{{vg_disk}}"
73
74 - name: Delete old LVMs if not mounted already
75   script: "{{role_path}}/scripts/old_vol_rm.sh"
76   args:
77     creates: /etc/partfs_rootdisk_created
78
79 - name: Creating LVM
80   lvol:
81     vg: VG
82     lv: "{{vol['lvm_name']}}"
83     size: "{{vol['lvm_size']}}"
84   with_items: "{{device_mapping|sort(attribute='mount_point')}}"
85   loop_control:
86     loop_var: vol
87   when:
88     - rerun_case.stat.exists is undefined or rerun_case.stat.exists == false
89
90 - name: Create XFS filesystem on LVM
91   filesystem:
92     fstype: xfs
93     dev: "/dev/mapper/VG-{{vol['lvm_name']}}"
94   with_items: "{{device_mapping|sort(attribute='mount_point')}}"
95   loop_control:
96     loop_var: vol
97
98 - name: Create fstab entry.
99   mount:
100     path: "{{vol['mount_point']}}"
101     src: "/dev/mapper/VG-{{vol['lvm_name']}}"
102     fstype: xfs
103     opts: "{{vol['mount_opts']}}"
104     state: present
105   with_items: "{{device_mapping|sort(attribute='mount_point')}}"
106   loop_control:
107     loop_var: vol
108
109 # Run below script to do the following tasks
110 #-  Stop existing services
111 #-  Move the current files to a tmp location
112 #-  mount LVM on mount dir
113 #-  restore old files
114 #-  Start old services
115 #- It creates logs in the target node at /tmp/vol_mgmt_logfile
116 - name: Running a script to remount volume on target dir
117   script: "{{role_path}}/scripts/vol_mgmt.sh {{vol['mount_point']}} /dev/mapper/VG-{{vol['lvm_name']}}"
118   with_items: "{{device_mapping|sort(attribute='mount_point')}}"
119   loop_control:
120     loop_var: vol
121   args:
122     creates: /etc/partfs_rootdisk_created
123
124 - name: Check if Root partition can grow
125   shell: "growpart --dry-run $(readlink -f {{root_disk}}) 1"
126   register: rootpart
127   ignore_errors: yes
128   args:
129     creates: /etc/partfs_rootdisk_created
130
131 - name: Grow Root partition
132   shell: "growpart $(readlink -f {{root_disk}}) 1"
133   when: rootpart.rc == 0
134   args:
135     creates: /etc/partfs_rootdisk_created
136
137 - name: Grow xfs filesystem on Root partition
138   command: "xfs_growfs /"
139   args:
140     creates: /etc/partfs_rootdisk_created