Skip to content
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

Fix Boolean values defaulting to False in collection #14493

Merged
merged 5 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions awx_collection/plugins/module_utils/controller_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,15 @@ def update_if_needed(self, existing_item, new_item, on_update=None, auto_exit=Tr
def create_or_update_if_needed(
self, existing_item, new_item, endpoint=None, item_type='unknown', on_create=None, on_update=None, auto_exit=True, associations=None
):
# Remove boolean values of certain specific types
# this is needed so that boolean fields will not get a false value when not provided
for key in list(new_item.keys()):
if key in self.argument_spec:
param_spec = self.argument_spec[key]
if 'type' in param_spec and param_spec['type'] == 'bool':
if new_item[key] is None:
new_item.pop(key)

if existing_item:
return self.update_if_needed(existing_item, new_item, on_update=on_update, auto_exit=auto_exit, associations=associations)
else:
Expand Down
19 changes: 19 additions & 0 deletions awx_collection/tests/integration/targets/host/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
that:
- "result is not changed"

- name: Modify the host as a no-op
host:
name: "{{ host_name }}"
inventory: "{{ inv_name }}"
register: result

- assert:
that:
- "result is not changed"

- name: Delete a Host
host:
name: "{{ host_name }}"
Expand All @@ -68,6 +78,15 @@
that:
- "result is changed"

- name: Use lookup to check that host was enabled
ansible.builtin.set_fact:
host_enabled_test: "lookup('awx.awx.controller_api', 'hosts/{{result.id}}/').enabled"

- name: Newly created host should have API default value for enabled
assert:
that:
- host_enabled_test

- name: Delete a Host
host:
name: "{{ result.id }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@
that:
- result is changed

- name: Use lookup to check that schedules was enabled
ansible.builtin.set_fact:
schedules_enabled_test: "lookup('awx.awx.controller_api', 'schedules/{{result.id}}/').enabled"

- name: Newly created schedules should have API default value for enabled
assert:
that:
- schedules_enabled_test

- name: Build a real schedule with exists
schedule:
name: "{{ sched1 }}"
Expand Down
Loading