Skip to content

Commit 97bc20e

Browse files
author
Ubuntu
committed
Add v2 of cloud facts playbook
1 parent ceefe7e commit 97bc20e

File tree

4 files changed

+235
-35
lines changed

4 files changed

+235
-35
lines changed

etc/kayobe/ansible.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ inject_facts_as_vars = False
1010
callbacks_enabled = ansible.posix.profile_tasks
1111
# Silence warning about invalid characters found in group names
1212
force_valid_group_names = ignore
13+
# Default value plus custom filter plugins path
14+
filter_plugins = $ANSIBLE_HOME/plugins/filter:/usr/share/ansible/plugins/filter:$KAYOBE_CONFIG_PATH/ansible/filter_plugins/
1315

1416
[inventory]
1517
# Fail when any inventory source cannot be parsed.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!usr/bin/env python3
2+
3+
from ansible.errors import AnsibleFilterError
4+
# from ansible.plugins.filter.core imprt FilterModule
5+
6+
class FilterModule(object):
7+
def filters(self):
8+
return {
9+
'group_hostvars_by_var':
10+
self.group_hostvars_by_var,
11+
'group_hostvars_by_host':
12+
self.group_hostvars_by_host
13+
}
14+
15+
def group_hostvars_by_var(self, hostvars, var, stdout=None):
16+
result = {}
17+
18+
for host in hostvars.keys():
19+
try:
20+
indiv_host_all = hostvars[host]
21+
indiv_host_var = indiv_host_all[var]
22+
if stdout is not None:
23+
indiv_host_var = indiv_host_var[stdout]
24+
if indiv_host_var not in result.keys():
25+
result[indiv_host_var] = [host]
26+
else:
27+
result[indiv_host_var].append(host)
28+
except KeyError as e:
29+
raise AnsibleFilterError(f"Variable {var} not found in hostvars: {e}")
30+
31+
return result
32+
33+
def group_hostvars_by_host(self, hostvars, var, stdout=None, hosts=None):
34+
result = {}
35+
36+
### Currently returns blank dict, try block doesn't appear to be working
37+
38+
if not hosts:
39+
hosts = hostvars.keys()
40+
41+
for host in hosts:
42+
try:
43+
indiv_host_vars = hostvars[host][var]
44+
if stdout is not None:
45+
indiv_host_vars = indiv_host_vars['stdout_lines']
46+
if indiv_host_vars:
47+
result[host] = indiv_host_vars
48+
else:
49+
result[host] = []
50+
51+
except KeyError as e:
52+
AnsibleFilterError(f"Host {host} not found in hostvars.keys(): {e}")
53+
54+
55+
return result
56+
57+
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
- name: Can the control host reach the internet?
3+
hosts: localhost
4+
gather_facts: true
5+
tasks:
6+
- name: Check internet connectivity
7+
ansible.builtin.shell:
8+
cmd: "ping stackhpc.com -c 3"
9+
register: internet_connectivity
10+
timeout: 5
11+
ignore_errors: true
12+
- name: Set internet connectivity fact
13+
set_fact:
14+
internet_connectivity: "{{ not internet_connectivity.failed }}"
15+
16+
- name: Get facts for seed node
17+
hosts: seed
18+
gather_facts: true
19+
tasks:
20+
- name: Is there a dedicated seed node?
21+
set_fact:
22+
seed_node_is_vm: "{{ ansible_facts.virtualization_role == 'guest' }}"
23+
24+
- name: Get facts
25+
hosts: all
26+
gather_facts: true
27+
tasks:
28+
- name: Get OS distribution
29+
set_fact:
30+
distribution: "{{ ansible_facts.distribution }}"
31+
- name: Get OS distribution release
32+
set_fact:
33+
distribution_release: "{{ ansible_facts.distribution_release }}"
34+
- name: Get kernel version
35+
ansible.builtin.shell:
36+
cmd: "uname -r"
37+
register: kernel_version
38+
- name: Get running contianers
39+
ansible.builtin.shell:
40+
cmd: "docker ps --format {% raw %}'{{.Names}}'{% endraw %}"
41+
become: true
42+
register: containers_list
43+
- name: Get facts for computes
44+
hosts: compute
45+
gather_facts: true
46+
tasks:
47+
- name: Check if hugepages enabled
48+
set_fact:
49+
hugepages_enabled: "{{ ansible_facts.cmdline }}"
50+
51+
- name: Gather Cloud Facts
52+
hosts: localhost
53+
gather_facts: true
54+
tasks:
55+
- name: Write facts to file
56+
vars:
57+
cloud_facts:
58+
internet_connectivity: "{{ internet_connectivity }}"
59+
seed_node_is_vm: "{{ hostvars[groups['seed'][0]]['seed_node_is_vm'] }}"
60+
distributions: "{{ hostvars | group_hostvars_by_var('distribution') }}"
61+
dist_releases: "{{ hostvars | group_hostvars_by_var('distribution_release') }}"
62+
kernel_versions: "{{ hostvars | group_hostvars_by_var('kernel_version','stdout') }}"
63+
deployed_containers: "{{ hostvars | group_hostvars_by_host('containers_list', 'stdout') }}"
64+
openstack_release: "{{ openstack_release }}"
65+
openstack_release_name: "{{ openstack_release_codename }}"
66+
ansible_control_host_is_vm: "{{ ansible_facts.virtualization_role == 'guest' }}"
67+
controller_count: "{{ groups['controllers'] | length }}"
68+
hypervisor_count: "{{ groups['hypervisors'] | length }}"
69+
monitoring_count: "{{ groups['monitoring'] | length }}"
70+
osd_count: "{{ groups['osds'] | length }}"
71+
compute_count: "{{ groups['compute'] | length }}"
72+
baremetal_count: "{{ groups['baremetal-compute'] | length }}"
73+
ceph_deployed: "{{ groups['ceph'] | length > 0 | bool }}"
74+
ceph_count: "{{ groups['ceph'] | length }}"
75+
ceph_release: "{{ cephadm_ceph_release }}"
76+
storage_hyperconverged: "{{ groups['controllers'] | intersect(groups['osds']) | length > 0 | bool }}"
77+
wazuh_enabled: "{{ groups['wazuh-agent'] | length > 0 | bool }}"
78+
# ngs_enabled_: "{{ 'genericswitch' in (kolla_neutron_ml2_mechanism_drivers | default([])) | bool }}"
79+
# # ABOVE LEADS TO ERROR: argument of type ''NoneType'' is not iterable. argument of type ''NoneType'' is not iterable'
80+
kayobe_managed_switches: "{{ groups['switches'] | length > 0 | bool }}"
81+
proxy_configured: "{{ http_proxy | bool or https_proxy | bool }}"
82+
bifrost_version: "{{ kolla_bifrost_source_version }}"
83+
internal_tls_enabled: "{{ kolla_enable_tls_internal }}"
84+
external_tls_enabled: "{{ kolla_enable_tls_external }}"
85+
firewalld_enabled_all: >-
86+
{{
87+
controller_firewalld_enabled and
88+
compute_firewalld_enabled and
89+
storage_firewalld_enabled and
90+
monitoring_firewalld_enabled and
91+
infra_vm_firewalld_enabled and
92+
seed_firewalld_enabled and
93+
seed_hypervisor_firewalld_enabled
94+
}}
95+
firewalld_enabled_any: >-
96+
{{
97+
controller_firewalld_enabled or
98+
compute_firewalld_enabled or
99+
storage_firewalld_enabled or
100+
monitoring_firewalld_enabled or
101+
infra_vm_firewalld_enabled or
102+
seed_firewalld_enabled or
103+
seed_hypervisor_firewalld_enabled
104+
}}
105+
stackhpc_package_repos_enabled: "{{ stackhpc_repos_enabled }}"
106+
pulp_tls_enabled: "{{ pulp_enable_tls }}"
107+
kolla_image_tags: "{{ kolla_image_tags }}"
108+
gpu_passthrough_enabled: "{{ gpu_group_map | length > 0 | bool }}"
109+
vGPU_enabled: "{{ groups['vgpu'] | length > 0 | bool }}"
110+
hugepages_enabled: "{{ hostvars | group_hostvars_by_host('hugepages_enabled', hosts=['compute']) }}"
111+
ansible.builtin.copy:
112+
content: "{{ cloud_facts | to_nice_json(sort_keys=false) }}"
113+
dest: ~/cloud-facts_2.json
Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,68 @@
11
---
2+
- name: Can the control host reach the internet?
3+
hosts: localhost
4+
gather_facts: true
5+
tasks:
6+
- name: Check internet connectivity
7+
ansible.builtin.command: "ping stackhpc.com -c 3"
8+
register: internet_connectivity
9+
timeout: 5
10+
ignore_errors: true
11+
12+
- name: Set internet connectivity fact
13+
ansible.builtin.set_fact:
14+
internet_connectivity: "{{ not internet_connectivity.failed }}"
15+
16+
- name: Get facts for seed node
17+
hosts: seed
18+
gather_facts: true
19+
tasks:
20+
- name: Is there a dedicated seed node?
21+
ansible.builtin.set_fact:
22+
seed_node_is_vm: "{{ ansible_facts.virtualization_role == 'guest' }}"
23+
24+
- name: Get facts
25+
hosts: all
26+
gather_facts: true
27+
tasks:
28+
- name: Get OS distribution
29+
ansible.builtin.set_fact:
30+
distribution: "{{ ansible_facts.distribution }}"
31+
32+
- name: Get OS distribution release
33+
ansible.builtin.set_fact:
34+
distribution_release: "{{ ansible_facts.distribution_release }}"
35+
36+
- name: Get kernel version
37+
ansible.builtin.command: "uname -r"
38+
register: kernel_version
39+
40+
- name: Get running contianers
41+
ansible.builtin.command: "docker ps --format {% raw %}'{{.Names}}'{% endraw %}"
42+
become: true
43+
register: containers_list
44+
45+
- name: Get facts for computes
46+
hosts: compute
47+
gather_facts: true
48+
tasks:
49+
- name: Check if hugepages enabled
50+
ansible.builtin.set_fact:
51+
hugepages_enabled: "{{ ansible_facts.cmdline }}"
52+
253
- name: Gather Cloud Facts
354
hosts: localhost
455
gather_facts: true
556
tasks:
657
- name: Write facts to file
758
vars:
859
cloud_facts:
9-
ansible_control_host_distribution: "{{ ansible_facts.distribution }}"
10-
ansible_control_host_distribution_release: "{{ ansible_facts.distribution_release }}"
60+
internet_connectivity: "{{ internet_connectivity }}"
61+
seed_node_is_vm: "{{ hostvars[groups['seed'][0]]['seed_node_is_vm'] | default('N/A') }}"
62+
distributions: "{{ hostvars | group_hostvars_by_var('distribution') }}"
63+
dist_releases: "{{ hostvars | group_hostvars_by_var('distribution_release') }}"
64+
kernel_versions: "{{ hostvars | group_hostvars_by_var('kernel_version','stdout') }}"
65+
deployed_containers: "{{ hostvars | group_hostvars_by_host('containers_list', 'stdout') }}"
1166
openstack_release: "{{ openstack_release }}"
1267
openstack_release_name: "{{ openstack_release_codename }}"
1368
ansible_control_host_is_vm: "{{ ansible_facts.virtualization_role == 'guest' }}"
@@ -22,41 +77,11 @@
2277
ceph_release: "{{ cephadm_ceph_release }}"
2378
storage_hyperconverged: "{{ groups['controllers'] | intersect(groups['osds']) | length > 0 | bool }}"
2479
wazuh_enabled: "{{ groups['wazuh-agent'] | length > 0 | bool }}"
80+
# ngs_enabled_: "{{ 'genericswitch' in (kolla_neutron_ml2_mechanism_drivers | default([])) | bool }}"
81+
# # ABOVE LEADS TO ERROR: argument of type ''NoneType'' is not iterable. argument of type ''NoneType'' is not iterable'
2582
kayobe_managed_switches: "{{ groups['switches'] | length > 0 | bool }}"
2683
proxy_configured: "{{ http_proxy | bool or https_proxy | bool }}"
2784
bifrost_version: "{{ kolla_bifrost_source_version }}"
28-
barbican_enabled: "{{ kolla_enable_barbican }}"
29-
nova_enabled: "{{ kolla_enable_nova }}"
30-
neutron_enabled: "{{ kolla_enable_neutron }}"
31-
ovs_enabled: "{{ kolla_enable_openvswitch }}"
32-
ovn_enabled: "{{ kolla_enable_ovn }}"
33-
glance_enabled: "{{ kolla_enable_glance }}"
34-
cinder_enabled: "{{ kolla_enable_cinder }}"
35-
keystone_enabled: "{{ kolla_enable_keystone }}"
36-
horizon_enabled: "{{ kolla_enable_horizon }}"
37-
fluentd_enabled: "{{ kolla_enable_fluentd }}"
38-
rabbitmq_enabled: "{{ kolla_enable_rabbitmq }}"
39-
mariadb_enabled: "{{ kolla_enable_mariadb }}"
40-
mariabackup_enabled: "{{ kolla_enable_mariabackup }}"
41-
memcached_enabled: "{{ kolla_enable_memcached }}"
42-
haproxy_enabled: "{{ kolla_enable_haproxy }}"
43-
keepalived_enabled: "{{ kolla_enable_keepalived }}"
44-
octavia_enabled: "{{ kolla_enable_octavia }}"
45-
designate_enabled: "{{ kolla_enable_designate }}"
46-
manila_enabled: "{{ kolla_enable_manila }}"
47-
magnum_enabled: "{{ kolla_enable_magnum }}"
48-
heat_enabled: "{{ kolla_enable_heat }}"
49-
ironic_enabled: "{{ kolla_enable_ironic }}"
50-
skyline_enabled: "{{ kolla_enable_skyline }}"
51-
blazar_enabled: "{{ kolla_enable_blazar }}"
52-
pulp_enabled: "{{ seed_pulp_container_enabled }}"
53-
opensearch_enabled: "{{ kolla_enable_opensearch }}"
54-
opensearch_dashboards_enabled: "{{ kolla_enable_opensearch_dashboards }}"
55-
influxdb_enabled: "{{ kolla_enable_influxdb }}"
56-
grafana_enabled: "{{ kolla_enable_grafana }}"
57-
prometheus_enabled: "{{ kolla_enable_prometheus }}"
58-
cloudkitty_enabled: "{{ kolla_enable_cloudkitty }}"
59-
telegraf_enabled: "{{ kolla_enable_telegraf }}"
6085
internal_tls_enabled: "{{ kolla_enable_tls_internal }}"
6186
external_tls_enabled: "{{ kolla_enable_tls_external }}"
6287
firewalld_enabled_all: >-
@@ -82,6 +107,9 @@
82107
stackhpc_package_repos_enabled: "{{ stackhpc_repos_enabled }}"
83108
pulp_tls_enabled: "{{ pulp_enable_tls }}"
84109
kolla_image_tags: "{{ kolla_image_tags }}"
110+
gpu_passthrough_enabled: "{{ gpu_group_map | length > 0 | bool }}"
111+
vGPU_enabled: "{{ groups['vgpu'] | length > 0 | bool }}"
112+
hugepages_enabled: "{{ hostvars | group_hostvars_by_host('hugepages_enabled', hosts=['compute']) }}"
85113
ansible.builtin.copy:
86114
content: "{{ cloud_facts | to_nice_json(sort_keys=false) }}"
87-
dest: ~/cloud-facts.json
115+
dest: ~/cloud-facts_2.json

0 commit comments

Comments
 (0)