有人可以帮助我实现以下目标吗?
我在ansible的库存文件中有不同的组。我需要在一个剧本中为一组执行几条命令,而为另一组执行几条命令。
我已经为单人小组执行编写了以下类似的剧本,这很好,但是我需要将所有内容合并为一个剧本。
---
- name: chekcing Service status
hosts: hari
tasks:
- name : service status
shell: systemctl status "{{item}}"
with_items:
- 'jboss_prod'
您能否建议。
对于不同组上的不同任务,您可以编写如下。
---
- hosts: host1
tasks:
- name : service status
shell: systemctl status "{{item}}"
with_items:
- 'jboss_prod'
- hosts: host2
tasks:
- name : service status
shell: systemctl status "{{item}}"
with_items:
- 'apache_prod'
如评论中所述,您也可以使用systemd模块来检查服务状态。例如:(来自ansible文档)
- name: Make sure a service is running
systemd:
state: started
name: httpd