EFI: Take into consideration the new GPT layout.
[ta/infra-ansible.git] / roles / partfs_rootdisk / tasks / main.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: Gather variables for each operating system
18   include_vars: "{{ item }}"
19   with_first_found:
20     - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
21     - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
22     - "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
23     - "{{ ansible_distribution | lower }}.yml"
24     - "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
25     - "{{ ansible_os_family | lower }}.yml"
26   tags:
27     - always
28
29 - name: Stop all cloud-init services and disable them
30   systemd:
31     name: "{{item}}"
32     enabled: no
33     state: stopped
34   with_items:
35     - "cloud-config"
36     - "cloud-final"
37     - "cloud-init"
38     - "cloud-init-local"
39
40 - name: Remove udev rule which enables dhcp on the first interface
41   file: path="/etc/udev/rules.d/70-persistent-net.rules" state=absent
42
43 - name: Remove interface configuration which use dhcp
44   shell: rm -f $(grep -li BOOTPROTO.*dhcp /etc/sysconfig/network-scripts/ifcfg-* | sort -u)
45
46 - name : Get system disk info
47   parted:
48     device: "{{root_disk}}"
49     unit: GB
50   register: root_disk_info
51
52 - debug:
53     msg: "root_disk_info: {{root_disk_info}}"
54
55 - set_fact:
56     sys_part: "{{ root_disk_info.partitions|selectattr('num', 'equalto', 1)|first }}"
57     sys_part_number: 1
58   when: root_disk_info.disk.table == "msdos"
59
60 - set_fact:
61     sys_part: "{{ root_disk_info.partitions|selectattr('num', 'equalto', 3)|first }}"
62     sys_part_number: 3
63   when: root_disk_info.disk.table == "gpt"
64
65 - debug:
66     msg: "sys_part = {{root_disk}}{{sys_part_number}}: {{sys_part}}"
67
68 - name: get volume pools
69   shell: dmsetup ls | awk '{print $1}'
70   register: volume_pools
71   ignore_errors: yes
72
73 - debug:
74     msg: "volume pools: {{ volume_pools.stdout_lines }}"
75
76 - name: Delete old LVMs if not mounted already
77   script: "{{role_path}}/scripts/old_vol_rm.sh"
78   args:
79     creates: /etc/partfs_rootdisk_created
80
81 - name: get volume groups
82   shell: "vgs -o vg_name --noheadings | sed 's/ //g'"
83   register: volumegroups
84   ignore_errors: yes
85
86 - debug:
87     msg: "volume groups: {{ volumegroups.stdout_lines }}"
88
89 - name: get volume pools
90   shell: dmsetup ls | awk '{print $1}'
91   register: volume_pools
92   ignore_errors: yes
93
94 - debug:
95     msg: "volume pools: {{ volume_pools.stdout_lines }}"
96
97 - name: remove old volume groups
98   include: remove_old_instance_vg.yml
99
100 - name: delete temporary partition
101   parted:
102     device: "{{root_disk}}"
103     number: "{{ sys_part_number|int + 1 }}"
104     state: absent
105   when: delete_partition is defined
106
107 - name: configure root volume groups
108   include: root_disk_volume_groups.yml
109   vars:
110     create_disk_part: True
111
112 - name: configure instance disk partition
113   parted:
114     device: "{{root_disk}}"
115     number: "{{instance_part_number}}"
116     part_start: "{{instance_part_start}}GB"
117     flags: [ lvm ]
118     state: present
119   when: rootdisk_vg_percentage != all_disk_size_for_volume_group_vg
120
121 - name: remove old volume groups
122   include: remove_old_instance_vg.yml
123
124 - name: create /etc/partfs_rootdisk_created file
125   command: touch /etc/partfs_rootdisk_created
126   args:
127     creates: /etc/partfs_rootdisk_created