-
Notifications
You must be signed in to change notification settings - Fork 59
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
Avoid using ansible_failed_task in rescue blocks #88
Avoid using ansible_failed_task in rescue blocks #88
Conversation
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.
lgtm
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.
lgtm
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.
looks good -- thanks
ansible_failed_task can contain unexpanded Jinja2 templates with variable references that were valid when the task failed, but not valid anymore when using the variable in the rescue block. In this case the problem is with task names (.name) that contain references to storage_provider. Unfortunately this completely prevents using ansible_failed_task even if not using the problematic attribute. Other attribute could have been used if this were not the case, like .tags, but until ansible/ansible#49942 is fixed, it is better to avoid using ansible_failed_task and use the only other special variable describing the failed task: ansible_failed_result. Eliminate the previous workaround to set storage_provider on the tasks that expand ansible_failed_task and use ansible_failed_result with a special value of msg instead. This has a disadvantage of having to use a special msg with the fail module, while usually it is just a free-form message. The fail module does not set another attribute of the result that could be used though, and it is cleaner than the previous workaround.
bbf1f2e
to
787f00c
Compare
Note to myself: this trick should be added to oasis-roles/meta_standards#19 |
ansible_failed_task
can contain unexpanded Jinja2 templates with variable references that were valid when the task failed, but not valid anymore when using the variable in therescue
block. In this case the problem is with task names (.name
) that contain references tostorage_provider
. Unfortunately this completely prevents usingansible_failed_task
even if not using the problematic attribute. Other attribute could have been used if this were not the case, like.tags
, but until ansible/ansible#49942 is fixed, it is better to avoid usingansible_failed_task
and use the only other special variable describing the failed task:ansible_failed_result
.Eliminate the previous workaround to set storage_provider on the tasks that expand
ansible_failed_task
and useansible_failed_result
with a special value ofmsg
instead. This has a disadvantage of having to use a specialmsg
with thefail
module, while usually it is just a free-form message. Thefail
module does not set another attribute of the result that could be used though, and it is cleaner than the previous workaround.