ansible - 我可以在 Ansible 任务中的特定主机或主机组上运行吗?
问题描述
我可以在 Ansible 任务中的特定主机或主机组上运行吗?
---
- hosts: all
become: yes
tasks:
- name: Disable tuned
hosts: client1.local
service:
name: tuned
enabled: false
state: stopped
无论如何它都不起作用。这是错误:
[root@centos7 ansible]# ansible-playbook playbook/demo.yaml
ERROR! conflicting action statements: hosts, service
The error appears to be in '/root/ansible/playbook/demo.yaml': line 24, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Disable tuned
^ here
解决方案
由于我对将主机组织成组有类似的要求,因此我发现以下方法对我有用。
首先,我根据我的环境、管理组和任务来构建我的库存。
存货
[infrastructure:children]
prod
qa
dev
[prod:children]
tuned_hosts
[tuned_hosts]
client1.local
然后我可以使用
剧本
---
- hosts: all
become: yes
tasks:
- name: Disable tuned
service:
name: tuned
enabled: false
state: stopped
when: ('tuned_hosts' in group_names) # or ('prod' in group_names)
以及类似的东西
when: ("dev" not in group_names)
取决于我试图实现的目标。
文档
推荐阅读
- svg - SVG:路径:Moveto(M)是相对于原点而不是绝对的网格
- google-chrome - 未下载到 PDF 的 FTP 链接
- c++ - C ++:对函数错误的未定义引用
- javascript - CubeJS PostgresDriver 身份验证失败,但它在终端中工作
- swift - Swift KVO:如何避免静态?
- javascript - html按钮单击以在javascript类中添加值
- angular - 角度路由 redirectTo 不适用于延迟加载
- java - 启动一个 Gradle 守护进程,2 个繁忙和 6 个停止的守护进程无法重用,使用 --status 获取详细信息
- .htaccess - 如何将我的 htaccess 文件配置为对无法识别的子域进行通配符捕获?
- c - 遇到了一些关于如何搜索链接列表的代码,并想了解这段代码