Custom message with assert?

399 views
Skip to first unread message

cpb...@gmail.com

unread,
Jul 21, 2015, 11:15:00 AM7/21/15
to ansible...@googlegroups.com
The title to the assert command is "Fail with custom message". However, no where do I see a parameter for a custom message. Is it possible to specify a custom message? The fail command has the same title and supports a custom message via the msg parameter.

chris brinley

unread,
Aug 17, 2015, 2:35:31 PM8/17/15
to Ansible Project
I came to the same thought based on the doc title and lack of msg var being specified in doc. At least as of version 1.9.2 (and it looks like probably going back since its inception based on git history) msg: var is actually supported but the doc is not complete.  The code for assert module actually checks for a msg var and uses it if present.

the following playbook works as a test case

---

- hosts: all

  vars:

    jboss:

#      environment: bar   #This value will fail

      environment: stage  #This value will work


  tasks:

    - name: use assert

      assert:

        that: jboss.environment in ['dev','qa','stage','prod']

        msg: "the environment value of `{{jboss.environment}}` was specified but only dev,qa,stage and prod are allowed values. Please update config."


    - name: ensure use an allowed environment is used

      fail:

        msg: "the environment value of `{{jboss.environment}}` was specified but only dev,qa,stage and prod are allowed values. Please update config."

      when: jboss.environment not in ['dev','qa','stage','prod']

Reply all
Reply to author
Forward
0 new messages