团队,我有以下任务,但我需要在列表中的输出中搜索sdd。列出输出,而我的断言失败。我只想打印一条消息sdd,但根据结果在此任务上找不到。
#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')
输出
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"
}
答案 0 :(得分:0)
我不好,我在做逻辑上的对立。不需要做。不是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')