0
votes

Team, I have below task but I need to search for sdd in its output which is a list. listing the output and my assert is failing. I just want to print a message sdd found and not found on this task based on result.

#Local volume provision sdd check on CPU node
      - name: "Verify LVP Mounts sdd exists on CPU Nodes for mount_device"
        shell: "mount | grep sdd"
        register: lvp_mount
        ignore_errors: yes
        failed_when: False
        delegate_to: "{{ item }}"
        with_items: "{{ groups['kube-cpu-node'] }}"

      - set_fact:
          sdd: lvp_mount.results[0].stdout_lines
        when: lvp_mount is succeeded
      - debug:
          var: lvp_mount.results[0].stdout_lines
      - debug:
          msg: "Assert SDD Mounts present"
        failed_when: lvp_mount.results[0].stdout_lines[0] is search('sdd')

output

 debug] *****************************************************************************************************************************
Wednesday 27 November 2019  23:19:36 +0000 (0:00:00.066)       0:00:04.251 ****
ok: [localhost] => {
    "lvp_mount.results[0].stdout_lines": [
        "/dev/sdd1 on /local-volumes/postgres/b5b296cf-02cd-41b3-b090-4e2dc77c6867 type ext4 (rw,relatime,data=ordered)"
    ]
}

TASK [services-pre-install-checks : debug] *****************************************************************************************************************************
Wednesday 27 November 2019  23:19:36 +0000 (0:00:00.066)       0:00:04.317 ****
fatal: [localhost]: FAILED! => {
    "msg": "Assert SDD Mounts present"
}
1

1 Answers

0
votes

My bad, I was doing opposite of logic. Need to do NOT. is not search('sdd')

      - name: "Verify LVP Mounts sdd exists on CPU Nodes for mount_device"
        shell: "mount | grep sdd"
        register: lvp_mount
        ignore_errors: yes
        failed_when: False
        delegate_to: "{{ item }}"
        with_items: "{{ groups['kube-cpu-node'] }}"
      - debug:
          msg: "Assert SDD Mounts present"
        failed_when: lvp_mount.results[0].stdout_lines[0] is not search('sdd')