It's quite true that we don't know "yes" means a string when specified as a
string to -e, and it would seem wrong to automatically boolean-ify it.
However, you can pass it in as JSON if you like, as -e does take JSON.
"But it seems that variables set in vars/main.yml are always converted to
strings"
This is not the case.
If you do things like x: "{{y}}"
Then yes, it doesn't know y is a bool unless you cast it.
This may provide a reasonable answer.
On Thu, Jan 2, 2014 at 6:44 AM, Joost Cassee <[email protected]> wrote:
> Hi,
>
> First of all, a very happy new year to all of you.
>
> I am trying to find a way to make it possible to add "-e force=yes" to an
> ansible-playbook command line to force certain things, like unpacking an
> archive, even if it has not changed. I want to add "when: force" to such
> tasks.
>
> My set-up is role-based, so the first thing a tried is adding force: false
> in defaults/main.yml for every role that uses the variable. Unfortunately,
> if I use "-e force=yes" the variable is not magically interpreted as a
> boolean. So I could use "when: force|bool", but I tried to avoid that by
> setting "forced: "{{ force | default(False) | bool }}" and using the
> "forced" variable instead of "force". But it seems that variables set in
> vars/main.yml are always converted to strings. See the files at
> https://gist.github.com/jcassee/8217906 and a full Ansible environment at
> https://letscrate.com/f/jcassee/github/ansible-issue.tar.gz
>
> Two question:
> 1) Is the conversion to strings a bug or expected behaviour?
> 2) What is the simplest way to tie "-e force=yes" to "when: force"?
>
> Regards,
> Joost
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
Michael DeHaan <[email protected]>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.