foreman-ansible-modules
foreman-ansible-modules copied to clipboard
Changing label of organziation
SUMMARY
Running against a katello 4.3 or 4.4 server my playbook tries to change the label of my organization if I have changed the label later in the playbook:
$ ansible-playbook first.yaml --limit foreman8.example.com --diff
PLAY [configure foreman server] **************************************************************************************************************************************************************************************************************
TASK [theforeman.foreman.organizations : Add organizations] **********************************************************************************************************************************************************************************
failed: [foreman8.example.com] (item={'name': 'ORG', 'label': 'ORG2', 'state': 'present'}) => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"}, "ansible_loop_var": "foreman_organizations_item", "changed": false, "error": {"errors": {"label": ["cannot be changed."]}, "full_messages": ["Label cannot be changed."], "id": 1}, "foreman_organizations_item": {"label": "ORG2", "name": "ORG", "state": "present"}, "msg": "Error while performing update on organizations: 422 Client Error: Unprocessable Entity for url: https://foreman8.example.com/katello/api/organizations/1"}
PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
foreman8.example.com : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
ANSIBLE VERSION
$ ansible --version
ansible 2.9.27
config file = /home/k/k111111/git/foreman-ansible/ansible.cfg
configured module search path = ['/home/k/k111111/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Nov 17 2021, 16:10:06) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
COLLECTION VERSION
Using latest version 3.3.0 from ansible-galaxy with some patches from pull requests.
KATELLO/FOREMAN VERSION
katello-4.4.0-1.el8.noarch
foreman-3.2.0-1.el8.noarch
STEPS TO REPRODUCE
Create an organization. Then change only the label and run the playbook again.
EXPECTED RESULTS
Don't try to change the organization label but print a warning like for the other resources:
[WARNING]: The following parameters are not supported by your server when performing update on repositories: {'label'}. They were ignored.
Interesting.
The "parameter not supported" warning is shown when the parameter is not in the list of accepted parameters for the executed action, published by the server.
For some reason, label is published in the list of parameters for update here, yet the server returns an error if you try to pass it.
Ultimately, I'd argue the apidoc published by the server is wrong.
But I wonder if we should introduce a notion of "write once" parameters and mark label as such here.
@mdellweg @ehelms thoughts?
I've filed https://projects.theforeman.org/issues/34859 and opened https://github.com/Katello/katello/pull/10084 to fix it at the origin.
At the least, the api doc should exclude the write once fields from upgrade. I wonder how the ansible module should handle it. Should it fail on the attempt, or should it ignore changing it? Maybe label is only valid for present_with_defaults
.
Yeah, in the cases where the write once field is absent from the apidoc (like in the repository controller), we just raise a "The following parameters are not supported by your server when performing update" warning and carry on.
This is what the above PR against Katello implements (and we could locally patch the APIdoc in the meantime).
I just wonder if in this very specific and common case we should either:
- have a more specific warning
- actually cleanly error out, telling the user "can't do what you requested"
this is fixed since katello 4.5, closing