团队,我需要在多个主机上执行多个命令。单个主机的情况下可以使用以下命令,但如何在多个主机上进行相同的迭代?
- name: "SMI Tests for ECC singlebit and double bit codes "
command: "smi --xml-format --query | grep retired_count | grep -v 0"
ignore_errors: no
register: _smi_ecc_result
failed_when: _smi_ecc_result.rc == 0
delegate_to: "{{ item }}"
with_items: "{{ groups['kube-gpu-node'] }}"
现在,我还有更多命令可以执行上面的修改方式,以使它在with_items进入的每个主机上完成。
例如: 命令:df -kh 命令:ls -ltr
- name: "multi_commands Tests for ECC singlebit and double bit codes "
command:
- "smi --xml-format --query | grep retired_count | grep -v 0"
- "df -kh"
- "ls -ltr"
ignore_errors: no
register: multi_commands_result
failed_when: multi_commands_result.rc == 0
delegate_to: "{{ item }}"
with_items: "{{ groups['kube-gpu-node'] }}"
但是出现语法错误。
答案 0 :(得分:1)
您可以在命令模块中使用argv here来传递多个命令,也可以使用shell来传递多个命令,如下所示。
- name: "multi_commands Tests for ECC singlebit and double bit codes "
shell: |
smi --xml-format --query | grep retired_count | grep -v 0
df -kh
ls -ltr
ignore_errors: no
register: multi_commands_result
failed_when: multi_commands_result.rc != 0
delegate_to: "{{ item }}"
with_items: "{{ groups['kube-gpu-node'] }}"