Initial commit
[ta/infra-ansible.git] / roles / bootstrap-host / tasks / check-requirements.yml
1 ---
2 # Copyright 2015, Rackspace US, Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 - name: Check for a supported Operating System
17   assert:
18     that:
19       - (ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'xenial') or
20         (ansible_os_family == 'RedHat' and ansible_distribution_major_version == '7')
21     msg: "The only supported platforms for this release are Ubuntu 16.04 LTS (Xenial) and CentOS 7 (WIP)"
22   tags:
23     - check-operating-system
24
25 - name: Identify the space available in /
26   shell: |
27     df -BK / | awk '/^[^Filesystem]/ {print $4}' | sed 's/K//'
28   when: bootstrap_host_data_disk_device == None
29   changed_when: false
30   register: root_space_available
31   tags:
32     - check-disk-size
33
34 # Convert root_space_available to bytes.
35 - name: Set root disk facts
36   set_fact:
37     host_root_space_available_bytes: "{{ ( root_space_available.stdout | int) * 1024 | int }}"
38   when:
39     - bootstrap_host_data_disk_device == None
40   tags:
41     - check-disk-size
42
43 - name: Set data disk facts
44   set_fact:
45     host_data_disk_sectors: "{{ (ansible_devices[bootstrap_host_data_disk_device]['sectors'] | int) }}"
46     host_data_disk_sectorsize: "{{ (ansible_devices[bootstrap_host_data_disk_device]['sectorsize'] | int) }}"
47   when:
48     - bootstrap_host_data_disk_device != None
49   tags:
50     - check-disk-size
51
52 # Calculate the size of the bootstrap_host_data_disk_device by muliplying sectors with sectorsize.
53 - name: Calculate data disk size
54   set_fact:
55     host_data_disk_size_bytes: "{{ ((host_data_disk_sectors | int) * (host_data_disk_sectorsize | int)) | int }}"
56   when: bootstrap_host_data_disk_device != None
57   tags:
58     - check-disk-size
59
60 # Convert bootstrap_host_data_disk_min_size to bytes.
61 - name: Set min size fact
62   set_fact:
63     host_data_disk_min_size_bytes: "{{ ((bootstrap_host_data_disk_min_size | int) * 1024**3) | int }}"
64   tags:
65     - check-disk-size
66
67 - name: Fail if there is not enough space available in /
68   assert:
69     that: |
70       (host_root_space_available_bytes | int) >= (host_data_disk_min_size_bytes | int)
71   when: bootstrap_host_data_disk_device == None
72   tags:
73     - check-disk-size
74
75 - name: Fail if there is not enough disk space available (disk specified)
76   assert:
77     that: |
78       (host_data_disk_size_bytes | int) >= (host_data_disk_min_size_bytes | int)
79   when: bootstrap_host_data_disk_device != None
80   tags:
81     - check-disk-size
82
83 - name: Ensure that the kernel has VXLAN support
84   modprobe:
85     name: vxlan
86     state: present
87   tags:
88     - check-vxlan