-
Notifications
You must be signed in to change notification settings - Fork 23
Gather cloud factsv2 #1869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stackhpc/2025.1
Are you sure you want to change the base?
Gather cloud factsv2 #1869
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!usr/bin/env python3 | ||
|
||
from ansible.errors import AnsibleFilterError | ||
# from ansible.plugins.filter.core imprt FilterModule | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
class FilterModule(object): | ||
def filters(self): | ||
return { | ||
'group_hostvars_by_var': | ||
self.group_hostvars_by_var, | ||
'group_hostvars_by_host': | ||
self.group_hostvars_by_host | ||
} | ||
|
||
def group_hostvars_by_var(self, hostvars, var, stdout=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add docstrings for these filters? |
||
result = {} | ||
|
||
for host in hostvars.keys(): | ||
try: | ||
indiv_host_all = hostvars[host] | ||
indiv_host_var = indiv_host_all[var] | ||
if stdout is not None: | ||
indiv_host_var = indiv_host_var[stdout] | ||
if indiv_host_var not in result.keys(): | ||
result[indiv_host_var] = [host] | ||
else: | ||
result[indiv_host_var].append(host) | ||
Comment on lines
+24
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
except KeyError as e: | ||
raise AnsibleFilterError(f"Variable {var} not found in hostvars: {e}") | ||
|
||
return result | ||
|
||
def group_hostvars_by_host(self, hostvars, var, stdout=None, hosts=None): | ||
result = {} | ||
|
||
### Currently returns blank dict, try block doesn't appear to be working | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
if not hosts: | ||
hosts = hostvars.keys() | ||
|
||
for host in hosts: | ||
try: | ||
indiv_host_vars = hostvars[host][var] | ||
if stdout is not None: | ||
indiv_host_vars = indiv_host_vars['stdout_lines'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indiv_host_vars = indiv_host_vars[stdout] |
||
if indiv_host_vars: | ||
result[host] = indiv_host_vars | ||
else: | ||
result[host] = [] | ||
|
||
except KeyError as e: | ||
AnsibleFilterError(f"Host {host} not found in hostvars.keys(): {e}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The raise AnsibleFilterError(f"Variable '{var}' not found for host '{host}': {e}") |
||
|
||
|
||
return result | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,68 @@ | ||
--- | ||
- name: Can the control host reach the internet? | ||
hosts: localhost | ||
gather_facts: true | ||
tasks: | ||
- name: Check internet connectivity | ||
ansible.builtin.command: "ping stackhpc.com -c 3" | ||
register: internet_connectivity | ||
timeout: 5 | ||
ignore_errors: true | ||
|
||
- name: Set internet connectivity fact | ||
ansible.builtin.set_fact: | ||
internet_connectivity: "{{ not internet_connectivity.failed }}" | ||
Comment on lines
+2
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two things to note here:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to extend it further, you could also add a |
||
|
||
- name: Get facts for seed node | ||
hosts: seed | ||
gather_facts: true | ||
tasks: | ||
- name: Is there a dedicated seed node? | ||
ansible.builtin.set_fact: | ||
seed_node_is_vm: "{{ ansible_facts.virtualization_role == 'guest' }}" | ||
|
||
- name: Get facts | ||
hosts: all | ||
gather_facts: true | ||
tasks: | ||
- name: Get OS distribution | ||
ansible.builtin.set_fact: | ||
distribution: "{{ ansible_facts.distribution }}" | ||
|
||
- name: Get OS distribution release | ||
ansible.builtin.set_fact: | ||
distribution_release: "{{ ansible_facts.distribution_release }}" | ||
|
||
- name: Get kernel version | ||
ansible.builtin.command: "uname -r" | ||
register: kernel_version | ||
|
||
- name: Get running contianers | ||
ansible.builtin.command: "docker ps --format {% raw %}'{{.Names}}'{% endraw %}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could fail if it runs on a host that doesn't have docker installed, so needs to account for that |
||
become: true | ||
register: containers_list | ||
|
||
- name: Get facts for computes | ||
hosts: compute | ||
gather_facts: true | ||
tasks: | ||
- name: Check if hugepages enabled | ||
ansible.builtin.set_fact: | ||
hugepages_enabled: "{{ ansible_facts.cmdline }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fact hugepages_enabled: "{{ 'hugepages' in ansible_facts.cmdline }}" |
||
|
||
- name: Gather Cloud Facts | ||
hosts: localhost | ||
gather_facts: true | ||
tasks: | ||
- name: Write facts to file | ||
vars: | ||
cloud_facts: | ||
ansible_control_host_distribution: "{{ ansible_facts.distribution }}" | ||
ansible_control_host_distribution_release: "{{ ansible_facts.distribution_release }}" | ||
internet_connectivity: "{{ internet_connectivity }}" | ||
Check warning on line 60 in etc/kayobe/ansible/get-cloud-facts.yml
|
||
seed_node_is_vm: "{{ hostvars[groups['seed'][0]]['seed_node_is_vm'] | default('N/A') }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accessing seed_node_is_vm: "{{ hostvars[groups['seed'][0]]['seed_node_is_vm'] | default('N/A') if groups['seed'] else 'N/A' }}" |
||
distributions: "{{ hostvars | group_hostvars_by_var('distribution') }}" | ||
dist_releases: "{{ hostvars | group_hostvars_by_var('distribution_release') }}" | ||
kernel_versions: "{{ hostvars | group_hostvars_by_var('kernel_version','stdout') }}" | ||
deployed_containers: "{{ hostvars | group_hostvars_by_host('containers_list', 'stdout') }}" | ||
openstack_release: "{{ openstack_release }}" | ||
openstack_release_name: "{{ openstack_release_codename }}" | ||
ansible_control_host_is_vm: "{{ ansible_facts.virtualization_role == 'guest' }}" | ||
|
@@ -22,41 +77,11 @@ | |
ceph_release: "{{ cephadm_ceph_release }}" | ||
storage_hyperconverged: "{{ groups['controllers'] | intersect(groups['osds']) | length > 0 | bool }}" | ||
wazuh_enabled: "{{ groups['wazuh-agent'] | length > 0 | bool }}" | ||
# ngs_enabled_: "{{ 'genericswitch' in (kolla_neutron_ml2_mechanism_drivers | default([])) | bool }}" | ||
# # ABOVE LEADS TO ERROR: argument of type ''NoneType'' is not iterable. argument of type ''NoneType'' is not iterable' | ||
Comment on lines
+80
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
kayobe_managed_switches: "{{ groups['switches'] | length > 0 | bool }}" | ||
Comment on lines
+80
to
82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd guess it's only defined if it's used, so could you add a check to first ensure |
||
proxy_configured: "{{ http_proxy | bool or https_proxy | bool }}" | ||
bifrost_version: "{{ kolla_bifrost_source_version }}" | ||
barbican_enabled: "{{ kolla_enable_barbican }}" | ||
nova_enabled: "{{ kolla_enable_nova }}" | ||
neutron_enabled: "{{ kolla_enable_neutron }}" | ||
ovs_enabled: "{{ kolla_enable_openvswitch }}" | ||
ovn_enabled: "{{ kolla_enable_ovn }}" | ||
glance_enabled: "{{ kolla_enable_glance }}" | ||
cinder_enabled: "{{ kolla_enable_cinder }}" | ||
keystone_enabled: "{{ kolla_enable_keystone }}" | ||
horizon_enabled: "{{ kolla_enable_horizon }}" | ||
fluentd_enabled: "{{ kolla_enable_fluentd }}" | ||
rabbitmq_enabled: "{{ kolla_enable_rabbitmq }}" | ||
mariadb_enabled: "{{ kolla_enable_mariadb }}" | ||
mariabackup_enabled: "{{ kolla_enable_mariabackup }}" | ||
memcached_enabled: "{{ kolla_enable_memcached }}" | ||
haproxy_enabled: "{{ kolla_enable_haproxy }}" | ||
keepalived_enabled: "{{ kolla_enable_keepalived }}" | ||
octavia_enabled: "{{ kolla_enable_octavia }}" | ||
designate_enabled: "{{ kolla_enable_designate }}" | ||
manila_enabled: "{{ kolla_enable_manila }}" | ||
magnum_enabled: "{{ kolla_enable_magnum }}" | ||
heat_enabled: "{{ kolla_enable_heat }}" | ||
ironic_enabled: "{{ kolla_enable_ironic }}" | ||
skyline_enabled: "{{ kolla_enable_skyline }}" | ||
blazar_enabled: "{{ kolla_enable_blazar }}" | ||
pulp_enabled: "{{ seed_pulp_container_enabled }}" | ||
opensearch_enabled: "{{ kolla_enable_opensearch }}" | ||
opensearch_dashboards_enabled: "{{ kolla_enable_opensearch_dashboards }}" | ||
influxdb_enabled: "{{ kolla_enable_influxdb }}" | ||
grafana_enabled: "{{ kolla_enable_grafana }}" | ||
prometheus_enabled: "{{ kolla_enable_prometheus }}" | ||
cloudkitty_enabled: "{{ kolla_enable_cloudkitty }}" | ||
telegraf_enabled: "{{ kolla_enable_telegraf }}" | ||
internal_tls_enabled: "{{ kolla_enable_tls_internal }}" | ||
external_tls_enabled: "{{ kolla_enable_tls_external }}" | ||
firewalld_enabled_all: >- | ||
|
@@ -82,6 +107,9 @@ | |
stackhpc_package_repos_enabled: "{{ stackhpc_repos_enabled }}" | ||
pulp_tls_enabled: "{{ pulp_enable_tls }}" | ||
kolla_image_tags: "{{ kolla_image_tags }}" | ||
gpu_passthrough_enabled: "{{ gpu_group_map | length > 0 | bool }}" | ||
vGPU_enabled: "{{ groups['vgpu'] | length > 0 | bool }}" | ||
hugepages_enabled: "{{ hostvars | group_hostvars_by_host('hugepages_enabled', hosts=['compute']) }}" | ||
ansible.builtin.copy: | ||
content: "{{ cloud_facts | to_nice_json(sort_keys=false) }}" | ||
dest: ~/cloud-facts.json | ||
dest: ~/cloud-facts_2.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets just keep this as cloud-facts.json There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shebang is missing a leading
/
. While this file is a filter plugin and not directly executed, it's a best practice to have a correct shebang for consistency and to prevent issues if it's ever executed directly.