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

Hi,

My problem is described here (MWE):
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

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

password: !!null

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

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.

Variables typically stringify when invoked

Something I’m looking to tweak soon.

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

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

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

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