Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible ambiguous env value

Tags:

ansible

I'm getting the following warning in Ansible:

[WARNING]: Non-string value found for env option. Ambiguous env options should be wrapped in quotes to avoid YAML parsing. This will become an error in Ansible 2.8. Key: PORT; value will be treated as: 12345

So I went and looked up the origin of this value and wrapped all instances of it in quotes. Or so I thought. I'm still getting the warning.

So I went to the place in the code where it appeared and it seems to be this:

docker_container:
  env: '{{ params | combine(extra_params, {"PORT": my_port|int + amount|int * 10 })}}'

This is a setup for dealing with multiple instances of the same container, each getting a unique port, as to not interfere with one another.

And I'm not sure how to fix that without breaking that setup. Can it be cast to string again after the calculation is done? Should I do it beforehand? What's the best option here?

like image 205
KdgDev Avatar asked Mar 04 '23 21:03

KdgDev


1 Answers

As the ansible documentation for the docker_container module under env states

Values which might be parsed as numbers, booleans or other types by the YAML parser must be quoted (e.g. "true") in order to avoid data loss.

so you have to convert your result to a quoted string.

env: '{{ params | combine(extra_params, {"PORT": (my_port|int + amount|int * 10) | string })}}'
like image 84
JGK Avatar answered May 18 '23 18:05

JGK