如何使用WHEN处理失败和传入ansible消息

如何使用WHEN处理失败和传入ansible消息,ansible,ansible-2.x,ansible-facts,Ansible,Ansible 2.x,Ansible Facts,团队,我的任务是检查坐骑。我有失败的条件工作,但我也需要报告通过条件时,坐骑存在。。我做错了什么 shell: "mount | grep sdd" register: lvp_mount ignore_errors: yes failed_when: False delegate_to: "{{ item }}" with_items: "{{ groups['kube-cpu-node'] }}"

团队,我的任务是检查坐骑。我有失败的条件工作,但我也需要报告通过条件时,坐骑存在。。我做错了什么

        shell: "mount | grep sdd"
        register: lvp_mount
        ignore_errors: yes
        failed_when: False
        delegate_to: "{{ item }}"
        with_items: "{{ groups['kube-cpu-node'] }}"
      - name: "Report status of mounts"
        fail:
          msg: |
            Mounts sdd not found
            Output of `mount | grep sdd`:
            {{ lvp_mount.stdout }}
            {{ lvp_mount.stderr }}
        when: lvp_mount is failed
      - name: "Success Report status of mounts"
        fail:
          msg: |
            Mounts sdd found
            Output of `mount | grep sdd`:
            {{ lvp_mount.stdout }}
            {{ lvp_mount.stderr }}
        when: lvp_mount is succeeded
输出:

TASK [team-services-pre-install-checks : Verify LVP Mounts sdd exists on CPU Nodes for mount_device] ************************************************************************
Wednesday 27 November 2019  18:20:14 +0000 (0:00:00.097)       0:00:03.959 ****
changed: [localhost -> cpu03] => (item=compute03)
[WARNING]: Consider using the mount module rather than running 'mount'.  If you need to use command because mount is insufficient you can add 'warn: false' to this command
task or set 'command_warnings=False' in ansible.cfg to get rid of this message.


TASK [team-services-pre-install-checks : Report status of mounts] ***********************************************************************************************************
Wednesday 27 November 2019  18:20:15 +0000 (0:00:01.210)       0:00:05.170 ****
skipping: [localhost]

TASK [team-services-pre-install-checks : Success Report status of mounts] ***************************************************************************************************
Wednesday 27 November 2019  18:20:15 +0000 (0:00:00.056)       0:00:05.226 ****
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout'\n\nThe error appears to be in '/k8s/baremetal/roles/teama-services-pre-install-checks/tasks/main.yml': line 120, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n        when: lvp_mount is failed\n      - name: \"Success Report status of mounts\"\n
解决方案2我试过了,但我想让它通过

      - name: "Success Report status of mounts"
        fail:
          msg: |
            Mounts sdd found
            Output of `mount | grep sdd`
        when: lvp_mount is succeeded
我看到了这个解决方案,但不确定如何将其应用到我的解决方案中?

由于您正在注册一个循环的结果,每个迭代都将存储在
lvp\u mount.results
下的列表中。尝试在
debug
任务中转储整个
lvp\u mount
变量,以了解我的意思。我还认为您可能希望在“成功”任务中使用
debug
而不是
fail
Wednesday 27 November 2019  18:46:58 +0000 (0:00:00.056)       0:00:05.321 ****
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Mounts sdd found\nOutput of `mount | grep sdd`:\n"}