Documenting variables expected by a role

29 views
Skip to first unread message

Greg Leclercq

unread,
Sep 12, 2014, 5:22:36 AM9/12/14
to ansible...@googlegroups.com
Dear Ansible enthousiasts,

When I write a role, I'd like to tell what are the variables that tasks and templates will use. To prevent the interruption of the playbook in the middle of the execution of a role because a variable is not set, I also want to ensure that the playbook defines all mandatory variables.

My current approach is to provide a file `tasks/init.yml` in the role with an assert command such as:

```yaml
- assert:
    that:
    - var != ''
  tags: ["check"]
```

Then I include the file in `tasks/main.yml`:

```yaml
- include: init.yml
- ...
```

I can check the role with `ansible-playbook -i inventory playbook.yml -t check`.

What do you think about that? Do you have best practices to solve the same problems?
Your feedback is welcome :).

Cheers,
- Greg

Michael DeHaan

unread,
Sep 12, 2014, 9:51:40 AM9/12/14
to ansible...@googlegroups.com
Assert would be fine to use here.

(For future reference, the mailing list doesn't format things in Markdown)


--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b0d0e1b3-2337-44c3-9bf3-bdb1de5332c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages