-
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
Conversation
97bc20e to
d199d9a
Compare
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.
It appears to have picked up some stray changes from another PR. You might need another rebase
|
/gemini review |
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.
Code Review
This pull request introduces a new playbook to gather more detailed facts about the cloud environment, supported by a new custom Ansible filter. While the overall direction is good, the new filter plugin in filters.py contains several issues, including a critical bug that silences errors, leftover debugging comments, and inconsistencies. The get-cloud-facts.yml playbook also has some potential problems, such as a misleading fact name and unsafe variable access that could lead to playbook failures. I have provided specific comments and code suggestions to address these issues and improve the robustness and clarity of the new code.
d199d9a to
1c70988
Compare
9949f32 to
8b1311e
Compare
8b1311e to
5cb8111
Compare
| indiv_host_vars = hostvars[host][var] | ||
| for key in indiv_host_vars.keys(): | ||
| if key == "skipped": | ||
| return {} |
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.
I think return here is just going to instantly exit the function completely and return an empty dictionary. I think you want continue. May have to refactor the loop a bit to get that to work properly though.
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.
Just to be clear, what's the intention with this bit of the loop?
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.
Its a way to handle hosts not having Docker installed (or any other service it might be checking). If the docker ps command is skipped then Ansible saves "skipped" to containers_list. This part of the loop catches that and returns an empty dict as the value for that host
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.
Ah, okay have you tested it? I'm concerned that return is going to exit the entire function and just ignore any future iterations of the loop
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.
Here's a quick example of what I mean:
def testfunc():
for i in range(10):
if not i == 3:
print(i)
else:
return i
return "complete"
output = testfunc()
print("Final output")
print(output)alex@alex-framework:/tmp$ python3 testo.py
0
1
2
Final output
3
The loop never gets past 3 because it returns too early
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.
Whereas continue will just skip the element:
alex@alex-framework:/tmp$ python3 testo.py
0
1
2
4
5
6
7
8
9
Final output
complete
5cb8111 to
1bfbb2b
Compare
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.
Looking good, just a few minor tweaks
| ansible.builtin.set_fact: | ||
| seed_node_is_vm: "{{ ansible_facts.virtualization_role == 'guest' }}" | ||
|
|
||
| - name: Get facts |
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.
Just to be extra clear
| - name: Get facts | |
| - name: Set facts for all hosts |
| - name: Get facts | ||
| hosts: all | ||
| gather_facts: true | ||
| tasks: |
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.
Needs a pass on spacing between these tasks. Sometimes there's no gap, sometimes there's two lines.
Should be one empty line between each task (no gap between the first task and the tasks: line)
| - name: Set internet connectivity fact | ||
| ansible.builtin.set_fact: | ||
| internet_connectivity: "{{ not successful_ping.failed }}" | ||
| - 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 }}" |
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.
I went looking for ways to deduplicate this and it turns out you can specify multiple facts in one task, see docs
So you can do:
| - name: Set internet connectivity fact | |
| ansible.builtin.set_fact: | |
| internet_connectivity: "{{ not successful_ping.failed }}" | |
| - 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: Set facts | |
| ansible.builtin.set_fact: | |
| internet_connectivity: "{{ not successful_ping.failed }}" | |
| distribution: "{{ ansible_facts.distribution }}" | |
| distribution_release: "{{ ansible_facts.distribution_release }}" | |
| hugepages_enabled: "{{ 'hugepages' in ansible_facts.cmdline }}" |
(note I've also added hugepages_enabled to my example)
| ansible.builtin.set_fact: | ||
| hugepages_enabled: "{{ 'hugepages' in ansible_facts.cmdline }}" | ||
|
|
||
| - name: Gather Cloud Facts |
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 name of this play is now a bit similar to the previous "gather facts" plays. I'd rename it to be a bit more clear
| - name: Gather Cloud Facts | |
| - name: Write cloud facts file |
| 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 }}" |
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.
Just by convention, lets keep all vars lowercase
| vGPU_enabled: "{{ groups['vgpu'] | length > 0 | bool }}" | |
| vgpu_enabled: "{{ groups['vgpu'] | length > 0 | bool }}" |
| @@ -0,0 +1,124 @@ | |||
| --- | |||
| - name: Get facts for control host | |||
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.
nit: Set facts rather than Get facts
| - name: Get facts for control host | |
| - name: Set facts for control host |
Applies to subsequent plays as well
| ansible.builtin.command: "uname -r" | ||
| register: kernel_version | ||
|
|
||
| - name: Check if docker is installed |
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.
nit: capitalisation
| - name: Check if docker is installed | |
| - name: Check if Docker is installed |
|
You'll also need to rebase this on stackhpc/2025.1. In a recent change, all the ansible playbooks were moved to separate sub-directories, so there's a conflict where the playbook moved |
Adds playbook to gather more advanced facts about a multinode cloud