Skip to content

Commit ddadf8c

Browse files
committed
Go back on generating libvirt hosts
Signed-off-by: Daniel Pawlik <dpawlik@redhat.com>
1 parent 63461a2 commit ddadf8c

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

roles/libvirt_manager/tasks/add_vm_to_inventory.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
- name: Add host to runtime inventory
3-
ansible.builtin.add_host:
4-
name: "{{ _full_host_name }}"
5-
groups: "{{ _group }}s"
6-
ansible_ssh_user: "{{ _ssh_user }}"
7-
ansible_host: "{{ _add_ansible_host | ternary(_ansible_host, omit) }}"
8-
vm_type: "{{ _group }}"
2+
#- name: Add host to runtime inventory
3+
# ansible.builtin.add_host:
4+
# name: "{{ _full_host_name }}"
5+
# groups: "{{ _group }}s"
6+
# ansible_ssh_user: "{{ _ssh_user }}"
7+
# ansible_host: "{{ _add_ansible_host | ternary(_ansible_host, omit) }}"
8+
# vm_type: "{{ _group }}"
99

1010
- name: Ensure group section exists
1111
ansible.builtin.lineinfile:

roles/libvirt_manager/tasks/generate_networking_data.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,52 @@
8383
# END MAC pre-generation management
8484
#
8585
# START generate all IPs using networking_mapper role/module
86+
- name: Inject all VMs in the inventory
87+
when:
88+
- (_cifmw_libvirt_manager_layout.vms[_vm_type].amount | default(1) | int) > 0
89+
vars:
90+
_vm_type: "{{ cifmw_libvirt_manager_all_vms[item.key] | default('none') }}"
91+
_std_group: "{{ (_vm_type == 'crc') | ternary('ocp', _vm_type) }}"
92+
_group: >-
93+
{{
94+
(cifmw_baremetal_hosts is defined and
95+
cifmw_baremetal_hosts[item.key] is defined) |
96+
ternary('baremetal', _std_group)
97+
}}
98+
_ocp_name: >-
99+
{{
100+
item.key | replace('_', '-') |
101+
replace('ocp-', '')
102+
}}
103+
_hostname: >-
104+
{{
105+
(item.key is match('^ocp.*')) |
106+
ternary(_ocp_name, item.key) |
107+
replace('_', '-')
108+
}}
109+
_ssh_user: >-
110+
{{
111+
_cifmw_libvirt_manager_layout.vms[_vm_type].admin_user |
112+
default(_cifmw_libvirt_manager_layout.vms[_vm_type].user) |
113+
default('zuul')
114+
}}
115+
_add_ansible_host: >-
116+
{{
117+
_cifmw_libvirt_manager_layout.vms[_vm_type].manage | default(true) and
118+
_cifmw_libvirt_manager_layout.vms[_vm_type].disk_file_name | default(_vm_type is not none) != 'blank'
119+
}}
120+
_ansible_host: "{{ _hostname }}.{{ inventory_hostname }}"
121+
ansible.builtin.add_host:
122+
name: "{{ item.key | replace('_', '-') }}"
123+
groups: "{{ _group }}s"
124+
ansible_ssh_user: "{{ _ssh_user }}"
125+
ansible_host: "{{ _add_ansible_host | ternary(_ansible_host, omit) }}"
126+
vm_type: "{{ _group }}"
127+
loop: "{{ cifmw_libvirt_manager_mac_map | dict2items }}"
128+
loop_control:
129+
label: "Adding {{ item.key }} to {{ _group }}s"
130+
131+
##
86132
- name: Inject all VMs in the inventory
87133
when:
88134
- (_cifmw_libvirt_manager_layout.vms[_vm_type].amount | default(1) | int) > 0
@@ -141,6 +187,7 @@
141187
-i {{ cifmw_libvirt_manager_tmp_inv_file }}
142188
-y --list > {{ cifmw_libvirt_manager_dst_inv_file }}
143189
190+
144191
- name: Generate all IPs based on MAC and networks
145192
vars:
146193
cifmw_networking_mapper_ifaces_info: >-

roles/networking_mapper/tasks/_gather_facts.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
when: "'ansible_host' in _instance_vars"
5454
ansible.builtin.setup:
5555
gather_subset:
56+
- min
5657
- network
5758
- platform
5859
delegate_to: "{{ item }}"

roles/networking_mapper/tasks/load_env_definition.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
---
22
- name: Load the Network Environment Definition from file if not given
3-
when: "cifmw_networking_env_definition is not defined"
3+
# when: "cifmw_networking_env_definition is not defined"
44
block:
5+
- name: Print current cifmw_networking_env_definition if defined - daniel
6+
when: "cifmw_networking_env_definition is defined"
7+
ansible.builtin.debug:
8+
msg: |
9+
{{ cifmw_networking_env_definition }}
10+
511
- name: Check for Networking Environment Definition file existence
612
ansible.builtin.stat:
713
path: "{{ cifmw_networking_mapper_networking_env_def_path }}"

0 commit comments

Comments
 (0)