-
Notifications
You must be signed in to change notification settings - Fork 169
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
Unable to unset compute_profile in hostgroups via ansible #969
Comments
We need to set |
I believe that is impossible, as ansible gives you |
however, documentation can always be improved. hint |
I dig a bit on this issue and it still exists for I used the following playbook to reproduce the issue: ---
- hosts: foreman
connection: local
gather_facts: no
vars:
foreman_admin: admin
foreman_validate_certs: False
foreman_server_url: "https://foreman.example.net"
tasks:
- name: create hostgroup
theforeman.foreman.hostgroup:
username: "{{ foreman_admin }}"
password: "{{ foreman_admin_password }}"
server_url: "{{ foreman_server_url }}"
validate_certs: "{{ foreman_validate_certs }}"
name: Test
locations:
- 0193
organizations:
- SPOCK
parameters:
- name: foo
parameter_type: string
value: bar
compute_profile: generic
state: present
- name: remove compute_profile from hostgroup
theforeman.foreman.hostgroup:
username: "{{ foreman_admin }}"
password: "{{ foreman_admin_password }}"
server_url: "{{ foreman_server_url }}"
validate_certs: "{{ foreman_validate_certs }}"
name: Test
locations:
- 0193
organizations:
- SPOCK
parameters:
- name: foo
parameter_type: string
value: bar
compute_profile: ''
state: present
ignore_errors: True
- name: remove organizations from hostgroup
theforeman.foreman.hostgroup:
username: "{{ foreman_admin }}"
password: "{{ foreman_admin_password }}"
server_url: "{{ foreman_server_url }}"
validate_certs: "{{ foreman_validate_certs }}"
name: Test
organizations: []
state: present
ignore_errors: True
- name: remove locations from hostgroup
theforeman.foreman.hostgroup:
username: "{{ foreman_admin }}"
password: "{{ foreman_admin_password }}"
server_url: "{{ foreman_server_url }}"
validate_certs: "{{ foreman_validate_certs }}"
name: Test
locations: []
state: present
ignore_errors: True
- name: add architecture to hostgroup
theforeman.foreman.hostgroup:
username: "{{ foreman_admin }}"
password: "{{ foreman_admin_password }}"
server_url: "{{ foreman_server_url }}"
validate_certs: "{{ foreman_validate_certs }}"
name: Test
architecture: amd64
state: present
ignore_errors: True
- name: remove architecture from hostgroup
theforeman.foreman.hostgroup:
username: "{{ foreman_admin }}"
password: "{{ foreman_admin_password }}"
server_url: "{{ foreman_server_url }}"
validate_certs: "{{ foreman_validate_certs }}"
name: Test
architecture: ''
state: present
ignore_errors: True
- name: remove hostgroup
theforeman.foreman.hostgroup:
username: "{{ foreman_admin }}"
password: "{{ foreman_admin_password }}"
server_url: "https://foreman.example.net"
validate_certs: "{{ foreman_validate_certs }}"
name: Test
state: absent
ignore_errors: True it leads me to the following normal output:
Debug output for the misbehaving tasks as followed:
and
This shows that it's not possible to unset string parameters with |
Yeah, I can see how that won't work for non-list-type params… We might need to specialcase |
I added the following tasks:
and this works. |
Yeah, it only fails for parameters that refer to other entities. So e.g. a domain referring to a subnet, or a hostgroup refering to an architecture. If you look at the code of the modules, it's those which have |
Do you feel like experimenting? diff --git plugins/module_utils/foreman_helper.py plugins/module_utils/foreman_helper.py
index abb23e77..ae2a4e46 100644
--- plugins/module_utils/foreman_helper.py
+++ plugins/module_utils/foreman_helper.py
@@ -622,6 +622,8 @@ class ForemanAnsibleModule(AnsibleModule):
return result
def find_resource_by(self, resource, search_field, value, **kwargs):
+ if not value and kwargs.get('failsafe', False):
+ return None
search = '{0}{1}"{2}"'.format(search_field, kwargs.pop('search_operator', '='), value)
return self.find_resource(resource, search, **kwargs)
This might do it, but completely untested. |
@evgeni I applied your patch to my work tree but unfortunately it doesn't help out. Same errors. |
SUMMARY
It's not possible to unset
compute_profile
field via ansible. If we setcompute_profile
either via Ui or via Ansible we have only the possibility to unset thecompute_profile
field tonull
via UI not via ansible.ISSUE TYPE
ANSIBLE VERSION
KATELLO/FOREMAN VERSION
APYPIE VERSION
STEPS TO REPRODUCE
compute_profile
set.compute_profile
in ansible module call toNone
EXPECTED RESULTS
Compute profile
in UI should showInherit ...
or isempty
ACTUAL RESULTS
Ansible runs into the following error:
The text was updated successfully, but these errors were encountered: