mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 02:17:37 -02:30
Fix : awx.awx.group preserve hosts fails when there are no hosts (#13913)
Co-authored-by: Sean Sullivan <ssulliva@redhat.com>
This commit is contained in:
@@ -170,9 +170,11 @@ def main():
|
|||||||
id_list.append(sub_obj['id'])
|
id_list.append(sub_obj['id'])
|
||||||
# Preserve existing objects
|
# Preserve existing objects
|
||||||
if (preserve_existing_hosts and relationship == 'hosts') or (preserve_existing_children and relationship == 'children'):
|
if (preserve_existing_hosts and relationship == 'hosts') or (preserve_existing_children and relationship == 'children'):
|
||||||
preserve_existing_check = module.get_all_endpoint(group['related'][relationship])
|
if group:
|
||||||
for sub_obj in preserve_existing_check['json']['results']:
|
preserve_existing_check = module.get_all_endpoint(group['related'][relationship])
|
||||||
id_list.append(sub_obj['id'])
|
for sub_obj in preserve_existing_check['json']['results']:
|
||||||
|
if 'id' in sub_obj:
|
||||||
|
id_list.append(sub_obj['id'])
|
||||||
if id_list:
|
if id_list:
|
||||||
association_fields[relationship] = id_list
|
association_fields[relationship] = id_list
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,12 @@
|
|||||||
group_name1: "AWX-Collection-tests-group-group1-{{ test_id }}"
|
group_name1: "AWX-Collection-tests-group-group1-{{ test_id }}"
|
||||||
group_name2: "AWX-Collection-tests-group-group2-{{ test_id }}"
|
group_name2: "AWX-Collection-tests-group-group2-{{ test_id }}"
|
||||||
group_name3: "AWX-Collection-tests-group-group3-{{ test_id }}"
|
group_name3: "AWX-Collection-tests-group-group3-{{ test_id }}"
|
||||||
|
group_name4: "AWX-Collection-tests-group-group4-{{ test_id }}"
|
||||||
inv_name: "AWX-Collection-tests-group-inv-{{ test_id }}"
|
inv_name: "AWX-Collection-tests-group-inv-{{ test_id }}"
|
||||||
host_name1: "AWX-Collection-tests-group-host1-{{ test_id }}"
|
host_name1: "AWX-Collection-tests-group-host1-{{ test_id }}"
|
||||||
host_name2: "AWX-Collection-tests-group-host2-{{ test_id }}"
|
host_name2: "AWX-Collection-tests-group-host2-{{ test_id }}"
|
||||||
host_name3: "AWX-Collection-tests-group-host3-{{ test_id }}"
|
host_name3: "AWX-Collection-tests-group-host3-{{ test_id }}"
|
||||||
|
host_name4: "AWX-Collection-tests-group-host4-{{ test_id }}"
|
||||||
|
|
||||||
- name: Create an Inventory
|
- name: Create an Inventory
|
||||||
inventory:
|
inventory:
|
||||||
@@ -21,6 +23,26 @@
|
|||||||
state: present
|
state: present
|
||||||
registuer: result
|
registuer: result
|
||||||
|
|
||||||
|
- name: Create a Host
|
||||||
|
host:
|
||||||
|
name: "{{ host_name4 }}"
|
||||||
|
inventory: "{{ inv_name }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Add Host to Group
|
||||||
|
group:
|
||||||
|
name: "{{ group_name1 }}"
|
||||||
|
inventory: "{{ inv_name }}"
|
||||||
|
hosts:
|
||||||
|
- "{{ host_name4 }}"
|
||||||
|
preserve_existing_hosts: true
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result is changed"
|
||||||
|
|
||||||
- name: Create Group 1
|
- name: Create Group 1
|
||||||
group:
|
group:
|
||||||
name: "{{ group_name1 }}"
|
name: "{{ group_name1 }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user