summaryrefslogtreecommitdiffstats
path: root/ansible/roles/infra_check_requirements/tasks/main.yml
blob: 991bd7383c3ee81e1c1e6244655df7ad0fe5cb5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright (c) 2018 Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- name: Reread system properties
  setup:

- name: Include
  include_vars:
    file: "{{ rs_file }}"
    name: infra_deploy_vars

- name: Store total CPU, RAM, Disk requested resources
  set_fact:
    vcpu_t: "{{ item.vcpus|int + vcpu_t | int }}"
    vram_t: "{{ item.ram|int + vram_t | int }}"
    disk_t: "{{ item.disk|int + disk_t | int }}"
  with_items: "{{ infra_deploy_vars.nodes }}"

- name: Fail if not enough RAM
  fail:
    msg: "Failed, not enough RAM, required: {{ vram_t }}, available {{ ansible_memory_mb.nocache.free }}"
  when: ansible_memory_mb.nocache.free < vram_t | int

- name: Fail if not enough CPU
  fail:
    msg: "Failed, not enough CPU, required: {{ vcpu_t }}, available {{ ansible_processor_vcpus }}"
  when: ansible_processor_vcpus < vcpu_t | int

- name: Define default network counter
  set_fact:
    num_default_network_detected: 0

- name: Increment counter for every default network detected
  set_fact:
    num_default_network_detected: "{{ num_default_network_detected | int + 1 }}"
  when:
    - item.default_gateway is defined
    - item.default_gateway == True
  with_items: "{{ infra_deploy_vars.networks }}"

- name: Fail if more than 1 or 0 default networks
  fail:
    msg: "Failed, there must be 1 default network: {{ num_default_network_detected }} detected"
  when: num_default_network_detected | int != 1

- name: Fail if not enough Disk space
  set_fact:
    disk_avail: "{% for mount in ansible_mounts if mount.mount == '/' %}{{ (mount.size_available/1024/1024) | int }}{% endfor %}"
- fail:
    msg: "Failed, not enough disk space, required {{ disk_t }}, available: {{ disk_avail }}"
  when: disk_avail|int < disk_t | int

- set_fact:
    ostack_nodes: "{{ ostack_nodes | default([]) + [item.openstack_node] }}"
  when: item.openstack_node is defined
  with_items: "{{ infra_deploy_vars.nodes }}"

# all-in-one node node type must be controller, multinode requires at least one controller and one compute node
- fail:
    msg: "OpenStack node types currently supported: controller, compute. Check input VMs file."
  when: ostack_nodes is undefined or ostack_nodes | length < 1

- fail:
    msg: "In all-in-one configuration OpenStack node type must be controller."
  when: ostack_nodes | length == 1 and 'controller' not in ostack_nodes

- fail:
    msg: "At least one controller and one compute node expected when total number of OpenStack nodes is more than one."
  when: ostack_nodes | length > 1 and not ('compute' in ostack_nodes and 'controller' in ostack_nodes)