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

Avoid using ansible_failed_task in rescue blocks #88

Merged

Conversation

pcahyna
Copy link
Member

@pcahyna pcahyna commented May 6, 2020

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.

Copy link
Contributor

@richm richm left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Collaborator

@yizhanglinux yizhanglinux left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Collaborator

@dwlehman dwlehman left a 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.
@pcahyna pcahyna force-pushed the eliminate-task-name-workaround branch from bbf1f2e to 787f00c Compare May 7, 2020 19:14
@pcahyna pcahyna merged commit 787f00c into linux-system-roles:master May 8, 2020
@pcahyna
Copy link
Member Author

pcahyna commented May 15, 2020

Note to myself: this trick should be added to oasis-roles/meta_standards#19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants