ansible多个with_items并在清单组中的所有主机上循环 [英] ansible multiple with_items and loop on all hosts in inventory group
本文介绍了ansible多个with_items并在清单组中的所有主机上循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
团队,我需要在多个主机上执行多个命令.单个主机的情况下可以使用下面的命令,但是如何在多个主机上迭代相同的主机呢?
Team, I have a situation where I need to execute multiple commands on multiple hosts. for singular host case am fine with below but how to iterate the same over multiple hosts?
- 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进入的每个主机上完成.
Now, i have more commands to execute how should i modify above such that it done those on each hosts coming in with_items.
例如: 命令:df -kh 命令:ls -ltr
ex: command: df -kh command: 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'] }}"
但是出现语法错误.
推荐答案
您可以使用argv 此处,以传递多个命令或使用shell传递多个命令,如下所示.
Either you can use argv here in the command module to pass multiple commands or use shell to pass multiple commands as below.
- 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'] }}"
这篇关于ansible多个with_items并在清单组中的所有主机上循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文