如何处理失败并通过WHEN传递ansible消息

团队,我有一个正在检查安装的任务。我有失败条件工作,但是当安装出现时我也需要报告通过条件。我在做什么错了?

        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
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"}

我看到了此解决方案,但不确定如何将其安装到我的产品中? Ansible Message Output based on task result

cmwapfang 回答:如何处理失败并通过WHEN传递ansible消息

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3019284.html

大家都在问