Skip to content

Commit f062c9f

Browse files
eduolivaresclaude
andcommitted
[libvirt_manager] Preserve existing inventory children when regenerating all-group.yml
The all-group.yml inventory file is regenerated during deployment, but this causes loss of inventory groups from previous operations (e.g., BGP routers, spines, leafs, undercloud nodes). This change extracts the all-group creation logic into a separate task file that checks for an existing file, slurps its content, generates the new template, and then recursively merges the children from both old and new files. This ensures all inventory groups are preserved across multiple deployment phases. Co-Authored-By: Claude Sonnet 4.5 <[email protected]> Signed-off-by: Eduardo Olivares <[email protected]>
1 parent db09965 commit f062c9f

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
- name: Check if all-group.yml already exists
2+
ansible.builtin.stat:
3+
path: "{{ cifmw_libvirt_manager_basedir }}/reproducer-inventory/all-group.yml"
4+
register: _all_group_stat
5+
6+
- name: Slurp existing all-group.yml if it exists
7+
when: _all_group_stat.stat.exists
8+
ansible.builtin.slurp:
9+
src: "{{ cifmw_libvirt_manager_basedir }}/reproducer-inventory/all-group.yml"
10+
register: _all_group_slurped
11+
12+
- name: Parse existing all-group.yml content
13+
when: _all_group_stat.stat.exists
14+
ansible.builtin.set_fact:
15+
_existing_all_group: "{{ _all_group_slurped['content'] | b64decode | from_yaml }}"
16+
17+
- name: Create new "all" group inventory file from template
18+
ansible.builtin.template:
19+
dest: "{{ cifmw_libvirt_manager_basedir }}/reproducer-inventory/all-group.yml"
20+
src: "all-inventory.yml.j2"
21+
mode: "0644"
22+
23+
- name: Merge existing children with newly generated content
24+
when: _all_group_stat.stat.exists
25+
block:
26+
- name: Slurp newly created all-group.yml
27+
ansible.builtin.slurp:
28+
src: "{{ cifmw_libvirt_manager_basedir }}/reproducer-inventory/all-group.yml"
29+
register: _new_all_group_slurped
30+
31+
- name: Parse new all-group.yml content
32+
ansible.builtin.set_fact:
33+
_new_all_group: "{{ _new_all_group_slurped['content'] | b64decode | from_yaml }}"
34+
35+
- name: Combine old and new children recursively
36+
ansible.builtin.set_fact:
37+
_merged_all_group:
38+
all:
39+
children: "{{ _existing_all_group.all.children | combine(_new_all_group.all.children, recursive=true) }}"
40+
41+
- name: Write merged all-group.yml
42+
ansible.builtin.copy:
43+
dest: "{{ cifmw_libvirt_manager_basedir }}/reproducer-inventory/all-group.yml"
44+
content: "{{ _merged_all_group | to_nice_yaml }}"
45+
mode: "0644"
46+
47+

roles/libvirt_manager/tasks/deploy_layout.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@
106106
src: "all-inventory.yml.j2"
107107
mode: "0644"
108108

109+
- name: Create "all" group inventory file
110+
ansible.builtin.include_tasks: create_all_group_inventory.yml
111+
109112
- name: Ensure storage pool is present.
110113
when:
111114
- (require_extra_disks | int) > 0

0 commit comments

Comments
 (0)