Skip to content

Update playbooks_error_handling.rst #2095

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

Merged
merged 2 commits into from
Mar 20, 2025

Conversation

S1ructure
Copy link
Contributor

Add example for using own variables in conditions

Related: https://forum.ansible.com/t/using-variables-in-changed-when-failed-when-directives/10652/3

From my point of view this information was not clear yet, that
a) custom variables can be used in conditionals as well
b) the {{ }} annotation has to be avoided

Add example for using own variables in conditions
@S1ructure S1ructure force-pushed the update-playboox-error-handling branch from 356a5b8 to 473045a Compare November 3, 2024 18:40
Copy link
Contributor

@oraNod oraNod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for adding this to the docs @S1ructure - I've made a few suggestions. I'd also wonder if this should go into the variables section of the docs, maybe here: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#referencing-simple-variables

As I mentioned in one of my suggestions, I think putting this in the error handling section focuses too much on resolving a warning rather than promoting the best way to do something, if that makes sense.


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 {% %}.``
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@samccann samccann added backport-2.16 Automatically create a backport for the stable-2.16 branch backport-2.17 Automatically create a backport for the stable-2.17 branch backport-2.18 Automatically create a backport for the stable-2.18 branch labels Mar 20, 2025
@samccann samccann merged commit 19c3ffa into ansible:devel Mar 20, 2025
11 checks passed
Copy link

patchback bot commented Mar 20, 2025

Backport to stable-2.16: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-2.16/19c3ffa9ff685d195a01494e59c7202a7164e82c/pr-2095

Backported as #2452

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Mar 20, 2025
* Update playbooks_error_handling.rst

Add example for using own variables in conditions

* Apply suggestions from code review

Co-authored-by: Don Naro <[email protected]>

---------

Co-authored-by: Sandra McCann <[email protected]>
Co-authored-by: Don Naro <[email protected]>
(cherry picked from commit 19c3ffa)
Copy link

patchback bot commented Mar 20, 2025

Backport to stable-2.17: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-2.17/19c3ffa9ff685d195a01494e59c7202a7164e82c/pr-2095

Backported as #2453

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Mar 20, 2025
* Update playbooks_error_handling.rst

Add example for using own variables in conditions

* Apply suggestions from code review

Co-authored-by: Don Naro <[email protected]>

---------

Co-authored-by: Sandra McCann <[email protected]>
Co-authored-by: Don Naro <[email protected]>
(cherry picked from commit 19c3ffa)
Copy link

patchback bot commented Mar 20, 2025

Backport to stable-2.18: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-2.18/19c3ffa9ff685d195a01494e59c7202a7164e82c/pr-2095

Backported as #2454

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Mar 20, 2025
* Update playbooks_error_handling.rst

Add example for using own variables in conditions

* Apply suggestions from code review

Co-authored-by: Don Naro <[email protected]>

---------

Co-authored-by: Sandra McCann <[email protected]>
Co-authored-by: Don Naro <[email protected]>
(cherry picked from commit 19c3ffa)
samccann pushed a commit that referenced this pull request Mar 20, 2025
* Update playbooks_error_handling.rst

Add example for using own variables in conditions

* Apply suggestions from code review

Co-authored-by: Don Naro <[email protected]>

---------

Co-authored-by: Sandra McCann <[email protected]>
Co-authored-by: Don Naro <[email protected]>
(cherry picked from commit 19c3ffa)

Co-authored-by: S1ructure <[email protected]>
samccann pushed a commit that referenced this pull request Mar 20, 2025
* Update playbooks_error_handling.rst

Add example for using own variables in conditions

* Apply suggestions from code review

Co-authored-by: Don Naro <[email protected]>

---------

Co-authored-by: Sandra McCann <[email protected]>
Co-authored-by: Don Naro <[email protected]>
(cherry picked from commit 19c3ffa)

Co-authored-by: S1ructure <[email protected]>
samccann pushed a commit that referenced this pull request Mar 20, 2025
* Update playbooks_error_handling.rst

Add example for using own variables in conditions

* Apply suggestions from code review

Co-authored-by: Don Naro <[email protected]>

---------

Co-authored-by: Sandra McCann <[email protected]>
Co-authored-by: Don Naro <[email protected]>
(cherry picked from commit 19c3ffa)

Co-authored-by: S1ructure <[email protected]>
felixfontein added a commit to felixfontein/ansible-documentation that referenced this pull request Mar 21, 2025
felixfontein added a commit that referenced this pull request Mar 21, 2025
* Add yamllint check for RST code listings.

* Address review comments.

* Sort languages and remove no longer needed duplicates.

* Enable warnings, but disable all failing rules.

* Improve formulation.

Co-authored-by: Don Naro <[email protected]>

* Show allowed languages when no or invalid language is supplied. Improve line lengths.

* Make sure that 'yamllint .' passes.

* Fix indentation issues introduced in #2095.

---------

Co-authored-by: Don Naro <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-2.16 Automatically create a backport for the stable-2.16 branch backport-2.17 Automatically create a backport for the stable-2.17 branch backport-2.18 Automatically create a backport for the stable-2.18 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants