Skip to content

Commit 9949f32

Browse files
UbuntuGavinHeff
authored andcommitted
Add v2 of cloud facts playbook
1 parent d14ef83 commit 9949f32

File tree

3 files changed

+129
-34
lines changed

3 files changed

+129
-34
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+
5+
class FilterModule(object):
6+
def filters(self):
7+
return {
8+
'group_hostvars_by_var':
9+
self.group_hostvars_by_var,
10+
'group_hostvars_by_host':
11+
self.group_hostvars_by_host
12+
}
13+
14+
def group_hostvars_by_var(self, hostvars, var, stdout=None):
15+
"""
16+
Returns a dictionary where the keys are values for the
17+
specified var in hostvars, and the values are the hosts
18+
that match that value.
19+
"""
20+
result = {}
21+
22+
for host in hostvars.keys():
23+
try:
24+
indiv_host_all = hostvars[host]
25+
indiv_host_var = indiv_host_all[var]
26+
if stdout is not None:
27+
indiv_host_var = indiv_host_var[stdout]
28+
result.setdefault(indiv_host_var, []).append(host)
29+
except KeyError as e:
30+
raise AnsibleFilterError(f"Variable {var} not found for host {host} in hostvars: {e}")
31+
32+
return result
33+
34+
def group_hostvars_by_host(self, hostvars, var, stdout=None, hostgroup=None):
35+
result = {}
36+
"""
37+
Returns a dictionary where the keys are hosts and the values
38+
are the values for the specified var in hostvars. If hosts is
39+
specified, only those hosts are included.
40+
"""
41+
for host in hostvars.keys():
42+
try:
43+
indiv_host_vars = hostvars[host][var]
44+
for key in indiv_host_vars.keys():
45+
if key == "skipped":
46+
return {}
47+
if stdout is not None:
48+
indiv_host_vars = indiv_host_vars[stdout]
49+
if indiv_host_vars:
50+
result[host] = indiv_host_vars
51+
else:
52+
result[host] = []
53+
54+
except KeyError as e:
55+
raise AnsibleFilterError(f"Variable {var} not found for host {host} in hostvars: {e}")
56+
57+
return result
Lines changed: 70 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,77 @@
11
---
2+
- name: Get facts for control host
3+
hosts: localhost
4+
gather_facts: true
5+
tasks:
6+
- name: Check if ngs enabled
7+
ansible.builtin.set_fact:
8+
ngs_enabled: >-
9+
{{ 'genericswitch' in kolla_neutron_ml2_mechanism_drivers | default(false) }}
10+
when: kolla_neutron_ml2_mechanism_drivers
11+
12+
- name: Get facts for seed node
13+
hosts: seed
14+
gather_facts: true
15+
tasks:
16+
- name: Is there a dedicated seed node?
17+
ansible.builtin.set_fact:
18+
seed_node_is_vm: "{{ ansible_facts.virtualization_role == 'guest' }}"
19+
20+
- name: Get facts
21+
hosts: all
22+
gather_facts: true
23+
tasks:
24+
- name: Pinging stackhpc.com to check internet connectivity
25+
ansible.builtin.command: "ping stackhpc.com -c 3"
26+
register: successful_ping
27+
timeout: 5
28+
ignore_errors: true
29+
30+
- name: Set internet connectivity fact
31+
ansible.builtin.set_fact:
32+
internet_connectivity: "{{ not successful_ping.failed }}"
33+
34+
- name: Get OS distribution
35+
ansible.builtin.set_fact:
36+
distribution: "{{ ansible_facts.distribution }}"
37+
38+
- name: Get OS distribution release
39+
ansible.builtin.set_fact:
40+
distribution_release: "{{ ansible_facts.distribution_release }}"
41+
42+
- name: Get kernel version
43+
ansible.builtin.command: "uname -r"
44+
register: kernel_version
45+
46+
- name: Check if docker is installed
47+
ansible.builtin.command: "which docker"
48+
register: docker_check
49+
failed_when: docker_check.rc not in [0]
50+
ignore_errors: true
51+
52+
- name: Get running contianers
53+
ansible.builtin.command: "docker ps --format {% raw %}'{{.Names}}'{% endraw %}"
54+
become: true
55+
register: containers_list
56+
when: not docker_check.failed
57+
58+
- name: Check if hugepages enabled
59+
ansible.builtin.set_fact:
60+
hugepages_enabled: "{{ 'hugepages' in ansible_facts.cmdline }}"
61+
262
- name: Gather Cloud Facts
363
hosts: localhost
464
gather_facts: true
565
tasks:
666
- name: Write facts to file
767
vars:
868
cloud_facts:
9-
ansible_control_host_distribution: "{{ ansible_facts.distribution }}"
10-
ansible_control_host_distribution_release: "{{ ansible_facts.distribution_release }}"
69+
internet_connectivity: "{{ hostvars | group_hostvars_by_var('internet_connectivity') }}"
70+
seed_node_is_vm: "{{ hostvars[groups['seed'][0]]['seed_node_is_vm'] | default('N/A') if groups ['seed'] else 'N/A' }}"
71+
distributions: "{{ hostvars | group_hostvars_by_var('distribution') }}"
72+
dist_releases: "{{ hostvars | group_hostvars_by_var('distribution_release') }}"
73+
kernel_versions: "{{ hostvars | group_hostvars_by_var('kernel_version','stdout') }}"
74+
deployed_containers: "{{ hostvars | group_hostvars_by_host('containers_list', 'stdout_lines') | default({}) }}"
1175
openstack_release: "{{ openstack_release }}"
1276
openstack_release_name: "{{ openstack_release_codename }}"
1377
ansible_control_host_is_vm: "{{ ansible_facts.virtualization_role == 'guest' }}"
@@ -22,41 +86,10 @@
2286
ceph_release: "{{ cephadm_ceph_release }}"
2387
storage_hyperconverged: "{{ groups['controllers'] | intersect(groups['osds']) | length > 0 | bool }}"
2488
wazuh_enabled: "{{ groups['wazuh-agent'] | length > 0 | bool }}"
89+
ngs_enabled: "{{ ngs_enabled | default(false) }}"
2590
kayobe_managed_switches: "{{ groups['switches'] | length > 0 | bool }}"
2691
proxy_configured: "{{ http_proxy | bool or https_proxy | bool }}"
2792
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 }}"
6093
internal_tls_enabled: "{{ kolla_enable_tls_internal }}"
6194
external_tls_enabled: "{{ kolla_enable_tls_external }}"
6295
firewalld_enabled_all: >-
@@ -82,6 +115,9 @@
82115
stackhpc_package_repos_enabled: "{{ stackhpc_repos_enabled }}"
83116
pulp_tls_enabled: "{{ pulp_enable_tls }}"
84117
kolla_image_tags: "{{ kolla_image_tags }}"
118+
gpu_passthrough_enabled: "{{ gpu_group_map | length > 0 | bool }}"
119+
vGPU_enabled: "{{ groups['vgpu'] | length > 0 | bool }}"
120+
hugepages_enabled: "{{ hostvars | group_hostvars_by_var('hugepages_enabled') }}"
85121
ansible.builtin.copy:
86122
content: "{{ cloud_facts | to_nice_json(sort_keys=false) }}"
87123
dest: ~/cloud-facts.json

0 commit comments

Comments
 (0)