Initial commit
[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 - set_fact:
47     root_disk_part1: "{% if root_disk == default_rootdisk_device %}{{root_disk}}{{first_part_number}}{% else %}{{root_disk}}-part{{first_part_number}}{% endif %}"
48
49 - name: get volume pools
50   shell: dmsetup ls | awk '{print $1}'
51   register: volume_pools
52   ignore_errors: yes
53
54 - debug:
55     msg: "volume pools: {{ volume_pools.stdout_lines }}"
56
57 - name: Delete old LVMs if not mounted already
58   script: "{{role_path}}/scripts/old_vol_rm.sh"
59   args:
60     creates: /etc/partfs_rootdisk_created
61
62 - name: get volume groups
63   shell: "vgs -o vg_name --noheadings | sed 's/ //g'"
64   register: volumegroups
65   ignore_errors: yes
66
67 - debug:
68     msg: "volume groups: {{ volumegroups.stdout_lines }}"
69
70 - name: get volume pools
71   shell: dmsetup ls | awk '{print $1}'
72   register: volume_pools
73   ignore_errors: yes
74
75 - debug:
76     msg: "volume pools: {{ volume_pools.stdout_lines }}"
77
78 - name: remove old volume groups
79   include: remove_old_instance_vg.yml
80
81 - name: delete temporary partition
82   parted:
83     device: "{{root_disk}}"
84     number: "{{delete_partition}}"
85     state: absent
86   when: delete_partition is defined
87
88 - name: system disk total size
89   shell: parted {{root_disk}} unit GB print | grep "Disk /dev/" | awk '{print $3}' | tr -d 'a-z,A-Z'
90   register: root_disk_total_size
91
92 - debug:
93     msg: "root_disk_total_size.stdout {{ root_disk_total_size.stdout }}"
94
95 - name: configure root volume groups
96   include: root_disk_volume_groups.yml
97   vars:
98     part_start: "{{second_part_start}}GiB"
99     part_end: "{{second_part_end}}GB"
100     phy_disk_part_number: 2
101     create_disk_part: True
102
103 - name: system disk first partition size
104   shell: parted {{root_disk_part1}} unit GB print | grep "Disk /dev/" | awk '{print $3}' | tr -d 'a-z,A-Z'
105   register: first_part
106
107 - debug:
108      msg: "first_part.stdout {{ first_part.stdout }}"
109
110 - name: configure instance disk partition
111   parted:
112     device: "{{root_disk}}"
113     number: 3
114     part_start: "{{third_part_start}}GB"
115     flags: [ lvm ]
116     state: present
117   when: rootdisk_vg_percentage != all_disk_size_for_volume_group_vg
118
119 - name: remove old volume groups
120   include: remove_old_instance_vg.yml
121
122 - name: create /etc/partfs_rootdisk_created file
123   command: touch /etc/partfs_rootdisk_created
124   args:
125     creates: /etc/partfs_rootdisk_created