我是 ansible 任务的新手,正在创建一个执行登录操作的 yml,如果登录失败,则需要调用一些脚本。
- name: Logging Action
shell: "/usr/local/bin/cqlsh -u xyzyx -p 1234abc"
register: loginoutput
ignore_errors: yes
no_log: True
- name: Run the cql script to create new user
shell: sh create-new-user.cql"
when: loginoutput|failed
对于上面的任务,我创建了运行良好的任务。
我的问题是,执行登录操作时 - 它失败并显示如下错误消息......
我不想显示日志消息,即使日志中没有任何失败的字符串。
我试过no_log: True
,这给出了
failed: [127.0.0.1] => {"censored": "由于 no_log 参数而隐藏结果", "changed": true, "rc": 1}
我不想在 o/p 中显示失败的字符串。
你不能。no_log: True
是最好的防止输出的方法。
如果有帮助的话,除了ignore_errors: yes
,有failed_when
您可以在其中准确定义任务失败的原因。我们的想法是从一开始就不让任务失败。
- name: Logging Action
shell: "/usr/local/bin/cqlsh -u xyzyx -p 1234abc"
register: loginoutput
failed_when: false
no_log: True
所以在这种情况下,任务永远不会失败(false
)但您可以提供任何复杂的条件,这可能基于任务的输出。
现在,任务没有失败,但返回码为cqlsh
还是1
,可以在下一个任务的条件下使用。
- name: Run the cql script to create new user
shell: sh create-new-user.cql"
when: loginoutput.rc == 1
理论上,这应该具有与以前相同的结果,只是第一个任务没有被标记为失败,因此no_log: True
应该会达到预期的效果。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)