-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update playbooks_error_handling.rst #2095
base: devel
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -172,9 +172,30 @@ You can also combine multiple conditions to override "changed" result. | |||||
- '"ERROR" in result.stderr' | ||||||
- result.rc == 2 | ||||||
|
||||||
If you want to introduce your own variables, to avoid repeating a certain term, you can simply reference them in your conditionals | ||||||
|
||||||
.. code-block:: yaml | ||||||
|
||||||
- name: Example playbook | ||||||
hosts: myHosts | ||||||
vars: | ||||||
log_path: /home/ansible/logfolder/ | ||||||
log_file: log.log | ||||||
|
||||||
tasks: | ||||||
- name: Create empty log file | ||||||
ansible.builtin.shell: mkdir {{ log_path }} || touch {{log_path }}{{ log_file }} | ||||||
register: tmp | ||||||
changed_when: | ||||||
- tmp.rc == 0 | ||||||
- 'tmp.stderr != "mkdir: cannot create directory ‘" ~ log_path ~ "’: File exists"' | ||||||
|
||||||
.. note:: | ||||||
Notice the missing ``{{ }}`` around log_path. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Just like ``when`` these two conditionals do not require templating delimiters (``{{ }}``) as they are implied. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could add a link to this section of the docs: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_conditionals.html#basic-conditionals-with-when |
||||||
|
||||||
Just like ``when`` these two conditionals do not require templating delimiters (``{{ }}``) as they are implied. | ||||||
If you still use them, ansible will raise a warning ``[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}.`` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should include the exact warning text here. Granted this might be helpful to users who search for the warning but it adds maintenance overhead to the docs. I also don't believe it's good practice to document errors and warnings - better to document just the behaviour. |
||||||
|
||||||
See :ref:`controlling_what_defines_failure` for more conditional syntax examples. | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.