我正在运行以下ansible
任务:
- name: Remove Jenkins
register: jenkins_delete
shell: "helm delete --purge --tls jenkins-{{ env_name }}"
retries: 2
delay: 20
until: jenkins_delete.rc == 0
failed_when: "'jenkins-{{ env_name }} not found' not in jenkins_delete.stderr"
如果我要查找的版本不存在,则失败,如下所示:
fatal: [localhost]: FAILED! => {"attempts": 5, "changed": true, "cmd": "helm delete --purge --tls jenkins-inception", "delta": "0:00:00.212773", "end": "2020-01-24 13:58:24.993134", "failed_when_result": true, "msg": "non-zero return code", "rc": 1, "start": "2020-01-24 13:58:24.780361", "stderr": "Error: release: \"jenkins-inception\" not found", "stderr_lines": ["Error: release: \"jenkins-inception\" not found"], "stdout": "", "stdout_lines": []}
我要使用的failed_when
条件不是要防止这种情况吗?
编辑:我也尝试了此方法,但没有成功:
- name: Remove Jenkins
register: jenkins_delete
shell: "helm delete --purge --tls jenkins-{{ env_name }}"
retries: 2
delay: 10
until: jenkins_delete.rc == 0 or jenkins_delete.stderr is regex("release:.+not found")
这很奇怪,因为似乎使用的regex
应该match stderr
中的字符串
答案 0 :(得分:0)
据我所知,jenkins-inception
中stderr
周围有引号:
"Error: release: \"jenkins-inception\" not found"
。
此正则表达式应匹配:
"jenkins-{{ env_name }}" not found