mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-08 02:01:31 -07:00
docker_container: improve log_options idempotency by converting to string (#54955)
* Warn when log_options values are not strings. * Add changelog. * Improve message. * Improve formatting and formulation of other messages. * Add test for warning. * Trying double escaping.
This commit is contained in:
parent
6ff4547489
commit
d64b17731d
3 changed files with 19 additions and 6 deletions
|
@ -1586,7 +1586,14 @@ class TaskParameters(DockerBaseClass):
|
|||
if self.log_options is not None:
|
||||
options['Config'] = dict()
|
||||
for k, v in self.log_options.items():
|
||||
options['Config'][k] = str(v)
|
||||
if not isinstance(v, string_types):
|
||||
self.client.module.warn(
|
||||
"Non-string value found for log_options option '%s'. The value is automatically converted to '%s'. "
|
||||
"If this is not correct, or you want to avoid such warnings, please quote the value." % (k, str(v))
|
||||
)
|
||||
v = str(v)
|
||||
self.log_options[k] = v
|
||||
options['Config'][k] = v
|
||||
|
||||
try:
|
||||
return LogConfig(**options)
|
||||
|
@ -1622,8 +1629,8 @@ class TaskParameters(DockerBaseClass):
|
|||
if self.env:
|
||||
for name, value in self.env.items():
|
||||
if not isinstance(value, string_types):
|
||||
self.fail("Non-string value found for env option. "
|
||||
"Ambiguous env options must be wrapped in quotes to avoid YAML parsing. Key: %s" % (name, ))
|
||||
self.fail("Non-string value found for env option. Ambiguous env options must be "
|
||||
"wrapped in quotes to avoid them being interpreted. Key: %s" % (name, ))
|
||||
final_env[name] = str(value)
|
||||
return final_env
|
||||
|
||||
|
@ -2761,8 +2768,8 @@ class AnsibleDockerClientContainer(AnsibleDockerClient):
|
|||
key_main = comp_aliases.get(key)
|
||||
if key_main is None:
|
||||
if key_main in all_options:
|
||||
self.fail(("The module option '%s' cannot be specified in the comparisons dict," +
|
||||
" since it does not correspond to container's state!") % key)
|
||||
self.fail("The module option '%s' cannot be specified in the comparisons dict, "
|
||||
"since it does not correspond to container's state!" % key)
|
||||
self.fail("Unknown module option '%s' in comparisons dict!" % key)
|
||||
if key_main in comp_aliases_used:
|
||||
self.fail("Both '%s' and '%s' (aliases of %s) are specified in comparisons dict!" % (key, comp_aliases_used[key_main], key_main))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue