# How to pass actual python type (such as None) in yaml using a variable

**URL:** <https://forum.ansible.com/t/how-to-pass-actual-python-type-such-as-none-in-yaml-using-a-variable/13660>\
**Category:** Ansible Project\
**Created:** [October 10, 2013, 9:57pm UTC](https://forum.ansible.com/t/how-to-pass-actual-python-type-such-as-none-in-yaml-using-a-variable/13660 "2013-10-10T21:57:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy1](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Andy1](https://forum.ansible.com/u/Andy1)\
**Post date:** [October 10, 2013, 9:57pm UTC](https://forum.ansible.com/t/how-to-pass-actual-python-type-such-as-none-in-yaml-using-a-variable/13660/1 "2013-10-10T21:57:25Z")

</div>

Hi,

My problem is described here (MWE):  
[http://pastebin.com/27k4HHaU](http://pastebin.com/27k4HHaU)

Some modules allow you to pass yaml’s null as a param which ends up as a python’s None. For instance the mysql\_user module here:

[https://github.com/ansible/ansible/blob/devel/library/database/mysql\_user#L164](https://github.com/ansible/ansible/blob/devel/library/database/mysql_user#L164)

won’t change the password when null is passed:

- name: setup.mysql  
mysql\_user:  
password: null

will only change privileges but not passwords (which the user may change). However if I pass a variable

- name: setup mysql  
mysql\_user:  
password: “{{ pw }}”

I can’t get it to work properly (as shown in the pastebin). This is with the latest devel.

Is there a way to get that behavior? Right now I have to create two lists (one which enforces passwords, one which does not).

Cheers

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [October 10, 2013, 9:58pm UTC](https://forum.ansible.com/t/how-to-pass-actual-python-type-such-as-none-in-yaml-using-a-variable/13660/2 "2013-10-10T21:58:57Z")

</div>

password: !!null

there are other ways, but this is probably easiest to remember.

---

<div class="post-metadata">

**Author:** ![Andy1](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Andy1](https://forum.ansible.com/u/Andy1)\
**Post date:** [October 10, 2013, 10:13pm UTC](https://forum.ansible.com/t/how-to-pass-actual-python-type-such-as-none-in-yaml-using-a-variable/13660/3 "2013-10-10T22:13:57Z")

</div>

I’m confused. I can pass already null. Can you give me a working example how to do that with variables? It seems ansible is not passing the type’s properly to the module, even though it does show python’s ‘None’ when using with\_items and passing and array of maps.

---

<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:** [October 10, 2013, 11:59pm UTC](https://forum.ansible.com/t/how-to-pass-actual-python-type-such-as-none-in-yaml-using-a-variable/13660/4 "2013-10-10T23:59:03Z")

</div>

Variables typically stringify when invoked

Something I’m looking to tweak soon.

Consider using “” to mean no value set and you’ll be ok.

---

<div class="post-metadata">

**Author:** ![Andy1](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Andy1](https://forum.ansible.com/u/Andy1)\
**Post date:** [October 11, 2013, 4:12pm UTC](https://forum.ansible.com/t/how-to-pass-actual-python-type-such-as-none-in-yaml-using-a-variable/13660/5 "2013-10-11T16:12:56Z")

</div>

So does that mean that the “null” I pass should actually not evaluate to python’s “None”? Does that mean my playbook is going to break in the future? What is the spec?  
I think I’ve kind of been misunderstood with this post. The actual issue is shown in detail in the pastebin link (if you have a second, run it’ll become clear). So I take it the “null” is just and accidental (undocumented) feature that I’m using? If not, and this is a feature, then I’d consider this behavior a bug since the variable substitution seems to loose the type at some point and it doesn’t look like there is a way to get it to behave properly.

FWIW, I just split up the mysql\_user in two calls (one which passes “null” directly and one which passes “{{ item.pw }}”).

Cheers

---

<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:** [October 11, 2013, 8:47pm UTC](https://forum.ansible.com/t/how-to-pass-actual-python-type-such-as-none-in-yaml-using-a-variable/13660/6 "2013-10-11T20:47:33Z")

</div>

IMHO, you shouldn’t be thinking about a “null” in Ansible.

It’s a memory management concept, and Ansible is not a programming language.
