Skip to content
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 #2094

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/docsite/rst/playbook_guide/playbooks_error_handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ If you have too many conditions to fit neatly into one line, you can split it in
(ret.stderr != '') or
(ret.rc == 10)

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. Conditionals are already executed in a templating context, which makes the ``{{ }}`` superflous.

If you still use ansible will raise a warning ``[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}.``

.. _override_the_changed_result:

Defining "changed"
Expand Down
Loading