Skip to content

Commit 661f1d1

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 5479216 commit 661f1d1

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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: Create new "all" group inventory file from template
13+
ansible.builtin.template:
14+
dest: "{{ cifmw_libvirt_manager_basedir }}/reproducer-inventory/all-group.yml"
15+
src: "all-inventory.yml.j2"
16+
mode: "0644"
17+
18+
- name: Merge existing children with newly generated content
19+
when: _all_group_stat.stat.exists
20+
block:
21+
- name: Slurp newly created all-group.yml
22+
ansible.builtin.slurp:
23+
src: "{{ cifmw_libvirt_manager_basedir }}/reproducer-inventory/all-group.yml"
24+
register: _new_all_group_slurped
25+
26+
- name: Write merged all-group.yml
27+
vars:
28+
_existing_all_group: "{{ _all_group_slurped['content'] | b64decode | from_yaml }}"
29+
_existing_all_group_dict:
30+
all:
31+
children: "{{ _existing_all_group.all.children }}"
32+
_new_all_group: "{{ _new_all_group_slurped['content'] | b64decode | from_yaml }}"
33+
_merged_all_group: "{{ _existing_all_group_dict | combine(_new_all_group, recursive=true) }}"
34+
ansible.builtin.copy:
35+
dest: "{{ cifmw_libvirt_manager_basedir }}/reproducer-inventory/all-group.yml"
36+
content: "{{ _merged_all_group | to_nice_yaml }}"
37+
mode: "0644"

roles/libvirt_manager/tasks/deploy_layout.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,7 @@
101101
label: "{{ item }}"
102102

103103
- name: Create "all" group inventory file
104-
ansible.builtin.template:
105-
dest: "{{ cifmw_libvirt_manager_basedir }}/reproducer-inventory/all-group.yml"
106-
src: "all-inventory.yml.j2"
107-
mode: "0644"
104+
ansible.builtin.include_tasks: create_all_group_inventory.yml
108105

109106
- name: Ensure storage pool is present.
110107
when:

0 commit comments

Comments
 (0)