-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Allow value to be bool where 'yes'/'no' are in choices #4220
Conversation
Thanks @tmshn for this PR. This module is maintained by the Ansible core team, so it can take a while for patches to be reviewed. Thanks for your patience. Core team: please review according to guidelines (http://docs.ansible.com/ansible/developing_modules.html#module-checklist) and comment with 'needs_revision' or merge as appropriate. [This message brought to you by your friendly Ansibull-bot.] |
Hi, Some initial thoughts:
Having an option that accepts bool(ish) and values just seems confusing |
@tmshn The type='bool' is definitely acceptable. I'll be proposing a patch to ansible/ansible that addresses some cases where type='bool' is the wrong answer in a moment. If that works for the majority of the cases we can look at any remaining cases to see what the least kludgey way to solve them is. For others reading this, the problem is that if you write your playbook and specify:
Then the yaml parser converts that no into a boolean. Then the module gets Arguably, the right way to fix this is to be explicit in your playbook that you're handling a string here:
key=value should also work although we don't usually like promoting its use:
|
@tmshn See if ansible/ansible#16961 fixes most of the modules in case (2) for you and doesn't cause further problems. If it looks good we can merge that and you can cut this PR down to the modules that still have issues. If they're all in case (1) I think it will then be good to merge. If there's still things in case(2) we'll have to evaluate each of them to see what the best strategy is. (Same thing for ansible/ansible-modules-extras#2593 ) |
uri: follow_redirects: no Will lead yaml to set follow_redirects=False. This is problematic when the module parameter is not a boolean value but a string. For instance: follow_redirects = dict(required=False, default='safe', choices=['all', 'safe', 'none', 'yes', 'no']), Our parameter validation code ends up getting follow_redirects="False" instead of "no". The 100% fix is for the user to quote their strings in playbooks like: uri: follow_redirects: "no" But we can fix quite a few common cases by trying to switch "False" back into the string that it was specified as. We only do this if there is only one correct choices value that could have been specified. In the follow_redirects example, a value of "True" only maps back to "yes" and a value of "False" only maps back to "no" so we can do this. If choices also contained "on" and "off" then we couldn't map back safely and would need to force the module author to change the module to handle this case. Fixes parts of the following PRs: * ansible/ansible-modules-core#4220 * ansible/ansible-modules-extras#2593
@abadger Your strategy in ansible/ansible#16191 looks great! I'll wait it to be merged, and then revise this PR. Thus, this pended PR needs_revision now. |
You mean I don't need to (or should not) update these modules? |
@tmshn Normally it doesn't make sense to update depreciated modules unless there is a major bug/security concern. People should be moving over to the newer modules. |
uri: follow_redirects: no Will lead yaml to set follow_redirects=False. This is problematic when the module parameter is not a boolean value but a string. For instance: follow_redirects = dict(required=False, default='safe', choices=['all', 'safe', 'none', 'yes', 'no']), Our parameter validation code ends up getting follow_redirects="False" instead of "no". The 100% fix is for the user to quote their strings in playbooks like: uri: follow_redirects: "no" But we can fix quite a few common cases by trying to switch "False" back into the string that it was specified as. We only do this if there is only one correct choices value that could have been specified. In the follow_redirects example, a value of "True" only maps back to "yes" and a value of "False" only maps back to "no" so we can do this. If choices also contained "on" and "off" then we couldn't map back safely and would need to force the module author to change the module to handle this case. Fixes parts of the following PRs: * ansible/ansible-modules-core#4220 * ansible/ansible-modules-extras#2593
uri: follow_redirects: no Will lead yaml to set follow_redirects=False. This is problematic when the module parameter is not a boolean value but a string. For instance: follow_redirects = dict(required=False, default='safe', choices=['all', 'safe', 'none', 'yes', 'no']), Our parameter validation code ends up getting follow_redirects="False" instead of "no". The 100% fix is for the user to quote their strings in playbooks like: uri: follow_redirects: "no" But we can fix quite a few common cases by trying to switch "False" back into the string that it was specified as. We only do this if there is only one correct choices value that could have been specified. In the follow_redirects example, a value of "True" only maps back to "yes" and a value of "False" only maps back to "no" so we can do this. If choices also contained "on" and "off" then we couldn't map back safely and would need to force the module author to change the module to handle this case. Fixes parts of the following PRs: * ansible/ansible-modules-core#4220 * ansible/ansible-modules-extras#2593 (cherry picked from commit 6db6edf)
Thanks @tmshn for this PR. Unfortunately, it is not mergeable in its current state due to merge conflicts. Please rebase your PR. When you are done, please comment with text 'ready_for_review' and we will put this PR back into review. For help on how to do this cleanly please see http://docs.ansible.com/ansible/community.html#contributing-code-features-or-bugfixes [This message brought to you by your friendly Ansibull-bot.] |
ansible/ansible#16191 has been merged. Good to continue on this one. |
…pgrade' argument on apt module.
faef7b0
to
b9b7cce
Compare
NOTE This pull request work on same issue as #2593 on ansible-modules-extras. Therefore, below comment is almost copy-and-paste.
ISSUE TYPE
COMPONENT NAMES
_docker
docker_container
docker_image
_nova_compute
cl_img_install
apt
I did not modify
uri
module, since'yes'
/'no'
choices offollow_redirects
argument is deprecated.ANSIBLE VERSION
SUMMARY
Many arguments from many modules has limited choices including
'yes'
and/or'no'
as a option. However, in some case, these are treated as string type; boolean values cause error.This pull request fix this problem, in the following two way:
1. Change type to bool
If choices are only
'yes'
and'no'
, this argument can be easily modified to bool type. Even parameter is passed as string, it will be converted to boolean, so it is 100% backward compatible.Modules:
_nova_compute
Example:
_nova_compute
module's case2. Add options to catch boolean
If choices contains other values than
'yes'
or'no'
, this argument should be kept to be treated as string. In this case, if you pass boolean argument here, it will be converted to'True'
or'False'
respectively. Therefore, adding them to the choices will solve the problem.Modules:
_docker
docker_container
docker_image
apt
Example:
apt
module's caseThe choices of
upgrade
argument ofapt
modules contain"safe"
,"full"
and"dist"
, so it cannot be treated as boolean.