0

Team, I have a task that is checking for mounts. I have fail condition working but i also need to report for pass condition when mounts are present.. what am i doing wrong?

        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

output:

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

Solution2 i tried: but I want it to pass

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

I see this solution but not sure how to fit it in mine? Ansible Message Output based on task result

AhmFM
  • 1,552
  • 3
  • 23
  • 53
  • 1
    Since you are registering results from a loop, each iteration will be stored in a list under `lvp_mount.results`. Try dumping the entire `lvp_mount` variable in a `debug` task to see what I mean. – Matt P Nov 27 '19 at 21:32
  • 1
    I also think you might want to use `debug` rather than `fail` for your "is succeeded" task – Matt P Nov 27 '19 at 21:33

0 Answers0