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

3,065 views
Skip to first unread message

Andy

unread,
Oct 10, 2013, 5:57:25 PM10/10/13
to ansible...@googlegroups.com
Hi,

My problem is described here (MWE):

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:


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

Brian Coca

unread,
Oct 10, 2013, 5:58:57 PM10/10/13
to ansible...@googlegroups.com
password: !!null

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

Andy

unread,
Oct 10, 2013, 6:13:57 PM10/10/13
to ansible...@googlegroups.com
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.

Michael DeHaan

unread,
Oct 10, 2013, 7:59:03 PM10/10/13
to ansible...@googlegroups.com
Variables typically stringify when invoked

Something I'm looking to tweak soon.

Consider using "" to mean no value set and you'll be ok.


--
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 ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Andy

unread,
Oct 11, 2013, 12:12:56 PM10/11/13
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Oct 11, 2013, 4:47:33 PM10/11/13
to ansible...@googlegroups.com
IMHO, you shouldn't be thinking about a "null" in Ansible.

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




Reply all
Reply to author
Forward
0 new messages