gpt4 book ai didi

error-handling - 当救援 block 在文件中时,"ansible_failed_task"& "ansible_failed_result"变量未定义

转载 作者:行者123 更新时间:2023-12-01 04:51:00 25 4
gpt4 key购买 nike

ansible_failed_taskansible_failed_result当在从 main.yml 调用的文件中使用块救援完成错误处理时,变量给出未定义的错误在 Ansible 角色中。

文件夹结构:

roles/
role-test/
main.yml
file_with_error_handling.yml
main.yml
- include file_with_error_handling.yml
file_with_error_handling.yml
- block:
# some code with error.
rescue:
debug:
msg: "Task- {{ ansible_failed_task }} failed with error {{ ansible_failed_result }}"
test.yml
- hosts: all
become: yes
roles:
- role-test

test.yml执行我收到以下错误:

fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'ansible_failed_result' is undefined\n\nThe error appears to have been in '/tmp/test/role-test/tasks/test_main.yml': line 32, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# msg: \"ansible_failed_task- {{ ansible_failed_task }}\"\n - debug:\n ^ here\n"}



我为 ansible_failed_task 得到了同样的错误多变的。

如果我复制 file_with_error_handling.yml的代码在 main.yml然后执行它,它工作正常。我得到了 ansible_failed_result 中的值和 ansible_failed_task .只有当我从文件中调用它时才会出现问题。

有没有办法可以显示这些变量的输出?

最佳答案

似乎它在 2.9 中又坏了:

]$ ansible --version && ansible-playbook broken.yml
ansible 2.9.0
python version = 2.7.17 (default, Oct 21 2019, 17:20:57) [GCC 9.2.1 20190827 (Red Hat 9.2.1-1)]

PLAY [localhost] ********************************************************************************************************************************************************************

TASK [Fail] *************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => changed=false
msg: test

TASK [debug] ************************************************************************************************************************************************************************
ok: [localhost] =>
ansible_failed_task: VARIABLE IS NOT DEFINED!

关于error-handling - 当救援 block 在文件中时,"ansible_failed_task"& "ansible_failed_result"变量未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41104241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com