# Using a "-e force=yes" flag

**URL:** <https://forum.ansible.com/t/using-a-e-force-yes-flag/14250>\
**Category:** Ansible Project\
**Created:** [January 2, 2014, 11:44am UTC](https://forum.ansible.com/t/using-a-e-force-yes-flag/14250 "2014-01-02T11:44:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [January 2, 2014, 11:44am UTC](https://forum.ansible.com/t/using-a-e-force-yes-flag/14250/1 "2014-01-02T11:44:20Z")

</div>

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](https://gist.github.com/jcassee/8217906) and a full Ansible environment at [https://letscrate.com/f/jcassee/github/ansible-issue.tar.gz](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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [January 2, 2014, 2:04pm UTC](https://forum.ansible.com/t/using-a-e-force-yes-flag/14250/2 "2014-01-02T14:04:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [January 2, 2014, 2:36pm UTC](https://forum.ansible.com/t/using-a-e-force-yes-flag/14250/3 "2014-01-02T14:36:30Z")

</div>

> 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.

Good idea, thanks.

> "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.

With casting, you mean using the bool filter when using the variable  
("{{ x | bool }}")? Or would you expect this to work in vars/main.yml:

x: "{{ y | bool} }"

Regards,  
Joost
