forked from bluebanquise/bluebanquise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bb_core.yml
142 lines (131 loc) · 7.84 KB
/
bb_core.yml
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Exctracted from BlueBanquise commones vars core plugin
bb_core_iceberg_naming: 'iceberg'
bb_core_equipment_naming: 'equipment'
bb_core_os_naming: 'os'
bb_core_hw_naming: 'hw'
bb_core_management_networks_naming: 'net'
bb_core_master_groups_naming: 'fn'
bb_core_managements_group_name: 'fn_management'
#############################################################
############ J2_ LOGIC
#####
### Groups
# List of master groups.
j2_master_groups_list: "{{ groups | select('match','^'+bb_core_master_groups_naming+'_.*') | list | unique | sort }}"
# List of equipment groups.
# Deprecated
j2_equipment_groups_list: "{{ (groups | select('match','^'+bb_core_equipment_naming+'_.*') | list | length | int > 0) | ternary(groups | select('match','^'+bb_core_equipment_naming+'_.*') | list | unique | sort, ['all']) }}"
# Host current equipment group.
# Deprecated
j2_node_equipment: "{{ (groups | select('match','^'+bb_core_equipment_naming+'_.*') | list | length | int > 0) | ternary(group_names | select('match','^'+bb_core_equipment_naming+'_.*') | list | unique | sort | first | default('') | replace(bb_core_equipment_naming + '_',''), 'all') }}"
### Network
## Resolution
# Resolution network. The network on which host can be ping by direct name. (ex: ping c001).
j2_node_main_resolution_network: "{{ network_interfaces[0].network | default(none) }}"
# Resolution address.
j2_node_main_resolution_address: "{{ (network_interfaces[0].ip4 | default('')).split('/')[0] | default(none) }}"
## Main network
# The network used by Ansible to deploy configuration (related to ssh).
# Also the network used by the host to get services ip.
j2_node_main_network: "{{ network_interfaces | default([]) | selectattr('network','defined') | selectattr('network','match','^'+j2_current_iceberg_network+'-[a-zA-Z0-9]+') | map(attribute='network') | list | first | default(none) }}"
# Main network interface. For consistency, we use j2_node_main_network as source.
j2_node_main_network_interface: "{{ network_interfaces[j2_node_main_network].interface | default(none) }}"
# Main address, same concept.
j2_node_main_address: "{{ network_interfaces[j2_node_main_network].ip4 | default(none) }}"
# Generate the nodes list, as a cache for network_interfaces
# Example:
# c001:
# alias: null
# bmc:
# ip4: 10.10.103.1
# mac: 2a:2b:3c:2d:5e:6f
# name: bc001
# network: net-admin
# current_iceberg: iceberg1
# global_alias: null
# icebergs_main_network_dict: null
# network_interfaces:
# - interface: enp1s0
# ip4: 10.10.3.1
# mac: 1a:2b:3c:4d:5e:9f
# network: net-admin
# node_main_resolution_address: 10.10.3.1
# This is a transverse j2 (j2_bb_), used as a cache fact
j2_bb_nodes: "{%- set bnodes = {} -%}
{%- for host in j2_hosts_range -%}
{%- do bnodes.update({
host: {
'network_interfaces': hostvars[host]['network_interfaces'] | default(none, true),
'node_main_resolution_address': hostvars[host]['j2_node_main_resolution_address'] | default(none, true),
'current_iceberg': hostvars[host]['j2_current_iceberg'] | default(none, true),
'icebergs_main_network_dict': hostvars[host]['j2_icebergs_main_network_dict'] | default({}, true),
'bmc': hostvars[host]['bmc'] | default(none, true),
'alias': hostvars[host]['alias'] | default(none, true),
'global_alias': hostvars[host]['alias'] | default(none, true)
}
}) -%}
{%- endfor -%}
{{ bnodes }}"
## Equipments
# Generate the list of nodes with their associated os and hw groups as values
# Example:
# c001:
# hw: hw_supermicro_XXX
# os: os_ubuntu_22.04_gpu
# This is a transverse j2 (j2_bb_), used as a cache fact
j2_bb_nodes_profiles: "{%- set bnodes_profiles = {} -%}
{%- for host in j2_hosts_range -%}
{%- set host_hw = (hostvars[host]['group_names'] | select('match','^'+bb_core_hw_naming+'_.*') | list | unique | sort | first) | default(none, true) -%}
{%- set host_os = (hostvars[host]['group_names'] | select('match','^'+bb_core_os_naming+'_.*') | list | unique | sort | first) | default(none, true) -%}
{%- set host_type = hostvars[host]['hw_equipment_type'] | default(none, true) -%}
{%- if host_hw is not none and host_os is not none -%}
{%- set host_ep = (host_hw + '_with_' + host_os) -%}
{%- else -%}
{%- set host_ep = none -%}
{%- endif -%}
{%- do bnodes_profiles.update({host: {'hw': host_hw, 'os': host_os, 'ep': host_ep, 'type': host_type}}) -%}
{%- endfor -%}
{{ bnodes_profiles }}"
# Generate the equipments that are existing combination of hardware and os profiles
# and store the list of associated nodes inside these equipments. Nodes without both hw_ and os_ are ignored.
# Example:
# hw_supermicro_XXX_os_ubuntu_22.04_gpu:
# - c001
# This is a transverse j2 (j2_bb_), used as a cache fact
# It is expected that the dependency fact be bb_nodes_profiles
# If the dependency fact was not already cached, it will not be used but that implies longuer calculations
j2_bb_equipments: "{%- set bequipments = {} -%}
{%- if bb_nodes_profiles is defined -%}
{%- set bnodes_profiles = bb_nodes_profiles -%}
{%- else -%}{# Calculate since not cached #}
{%- set bnodes_profiles = j2_bb_nodes_profiles -%}
{%- endif -%}
{%- for host, host_keys in bnodes_profiles.items() -%}
{%- if host_keys['ep'] is not none -%}
{%- if host_keys['ep'] not in bequipments -%}
{%- do bequipments.update({host_keys['ep']: {'nodes': [], 'type': host_keys['type'], 'hw': host_keys['hw'], 'os': host_keys['os']}}) -%}
{%- endif -%}
{{ bequipments[host_keys['ep']]['nodes'].append(host) }}
{%- endif -%}
{%- endfor -%}
{{ bequipments }}"
## Other
# List of management networks.
j2_management_networks: "{{ networks | select('match','^'+j2_current_iceberg_network+'-[a-zA-Z0-9]+') | list | unique | sort }}"
### Icebergs engine file
# List all icebergs
j2_icebergs_groups_list: "{{ groups | select('match','^'+bb_core_iceberg_naming+'[a-zA-Z0-9]+') | list }}"
# Get total number of icebergs
j2_number_of_icebergs: "{{ groups | select('match','^'+bb_core_iceberg_naming+'[a-zA-Z0-9]+') | list | length }}"
# Grab current iceberg group
j2_current_iceberg: "{{ bb_icebergs_system | default(false) | ternary( group_names | select('match','^'+bb_core_iceberg_naming+'[a-zA-Z0-9]+') | list | unique | sort | first | default(bb_core_iceberg_naming+'1'), bb_core_iceberg_naming+'1') }}"
# Grab current iceberg number
j2_current_iceberg_number: "{{ j2_current_iceberg | replace(bb_core_iceberg_naming,' ') | trim }}"
# Grab current iceberg networks pattern
j2_current_iceberg_network: "{{ bb_icebergs_system | default(false) | ternary(bb_core_management_networks_naming + (j2_current_iceberg_number | string), bb_core_management_networks_naming) }}"
# Generate list of managements connected to this iceberg from sub icebergs
j2_iceberg_sub_managements_members: "{% set range = [] %}{% for host in (groups[bb_core_managements_group_name] | default([])) %}{% if (hostvars[host]['bb_iceberg_master'] | default(none)) == j2_current_iceberg %}{{ range.append(host) }}{% endif %}{% endfor %}{{ range }}"
# Generate range of hosts to include in current configurations
j2_hosts_range: "{{ ((bb_icebergs_system | default(false)) == true and (bb_iceberg_hosts_range | default('all')) == 'iceberg') | ternary( j2_iceberg_sub_managements_members + groups[j2_current_iceberg] | default([]), groups['all']) }}"
# Generate a dict that contains host main network for each iceberg
j2_icebergs_main_network_dict: "{{ '{' }}{% for iceberg in (j2_icebergs_groups_list | default([])) %}{% if not loop.first %},{% endif %}'{{ iceberg }}':'{{ network_interfaces | default([]) | selectattr('network', 'defined') | selectattr('network', 'match', '^'+(bb_icebergs_system | default(false) | ternary(bb_core_management_networks_naming + (iceberg | replace(bb_core_iceberg_naming, ' ') | trim | string), bb_core_management_networks_naming) )+'-[a-zA-Z0-9]+') | map(attribute='network') | list | first | default(none) }}'{% endfor %}{{ '}' }}"