エラーメッセージ内に特定の文字列がある場合に失敗を無視するにはどうすればよいですか?
stdout_lines:
failed: [lab_ansible] => {"ansible_loop_var": "item", "changed": true, "cmd": "cmd-agent stop lz", "delta": "0:00:02.398303", "end": "2020-07-14 13:17:04.858006", "failed_when_result": true, "item": "lz", "msg": "non-zero return code", "rc": 2, "start": "2020-07-14 13:17:02.459703", "stderr": "", "stderr_lines": [], "stdout": "Processing. Please wait...\nStopping Monitoring Agent for Linux OS ...\nAgent is not running...", "stdout_lines": ["Processing. Please wait...", "Stopping Monitoring Agent for Linux OS ...", "Agent is not running..."]}
暫定の:
- name: "Stopping agent"
shell: cmd-agent stop lz
register: stopped_lz
failed_when: ( stopped_lz.stdout_lines not in ['Agent is not running...', 'Agent stopped...'] )
上記のように、プレイブックは失敗のためにまだ閉じられています
したがって、要件に従って、エージェントが停止しているかどうかを確認しています。エージェントがまだ実行中の場合は、プレイブックの実行に失敗するはずです。そうでない場合は、合格する必要があります。以下のサンプルスクリプトは、要件を満たすのに役立つと思います。
---
- hosts: all
name: "[ Playbook Example ]"
gather_facts: false
vars:
- failure_message: "Agent is not running"
tasks:
- name: "[ Verify Failure Message ]"
command: "echo The failure message is {{ failure_message }}"
register: failure_reg
failed_when:
- "'Agent is not running' not in failure_reg.stdout"
- "'Agent stopped' not in failure_reg.stdout"
- debug:
msg: "{{ failure_reg.stdout }}"
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加