Simple assert failure

14 views
Skip to first unread message

John Harmon

unread,
Nov 8, 2019, 4:12:54 PM11/8/19
to Ansible Project
Simple, but I can't figure it out.  The following doesn't appear to be working.  Wondering if I have a syntax error?

- assert:
    that:
      - user is defined
    msg: "Be sure to define the username under defaults/main.yml"

Whether it is defined or not in the defaults/main.yml it produces the following:

ok: [localhost] => {
    "changed": false,
    "msg": "All assertions passed"
}


It DOES work if I delete the variable completely instead of just leaving it empty

Thanks in advance

Matt Martz

unread,
Nov 8, 2019, 4:17:56 PM11/8/19
to ansible...@googlegroups.com
Listing a variable, even as an empty value, still defines it.  It can only be undefined, if it hasn't been listed at all.

You can add a check that is something like the following also:

- user is not none

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/eafd1827-d142-40ae-8303-2913bba72ad7%40googlegroups.com.


--
Matt Martz
@sivel
sivel.net

John Harmon

unread,
Nov 8, 2019, 4:38:24 PM11/8/19
to Ansible Project
Perfect, thank you


On Friday, November 8, 2019 at 2:17:56 PM UTC-7, Matt Martz wrote:
Listing a variable, even as an empty value, still defines it.  It can only be undefined, if it hasn't been listed at all.

You can add a check that is something like the following also:

- user is not none

On Fri, Nov 8, 2019 at 3:13 PM John Harmon <jharmon...@gmail.com> wrote:
Simple, but I can't figure it out.  The following doesn't appear to be working.  Wondering if I have a syntax error?

- assert:
    that:
      - user is defined
    msg: "Be sure to define the username under defaults/main.yml"

Whether it is defined or not in the defaults/main.yml it produces the following:

ok: [localhost] => {
    "changed": false,
    "msg": "All assertions passed"
}


It DOES work if I delete the variable completely instead of just leaving it empty

Thanks in advance

--
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...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages