针对单个主机运行Ansible playbook

Son*_*ton 9 ansible

我正在使用hosts静态库存文件:

server1 ansible_ssh_host=1.1.1.1
server2 ansible_ssh_host=1.1.1.2
server3 ansible_ssh_host=1.1.1.3

[group1]
server1
server2
Run Code Online (Sandbox Code Playgroud)

而且我有一个example.yml像这样的剧本:

---
- name: base setup
  become: true
  hosts:
    - group1
  roles:
    - base
Run Code Online (Sandbox Code Playgroud)

我想ansible-playbook使用测试运行example.yml,但针对主机server1.有办法做到这一点吗?

Son*_*ton 15

好吧,我写完了这个问题,然后我的SO搜索功能得到了改进.以下是一些答案:

使用-l SUBSET:

在特定服务器组上运行Ansible Playbook

使用-i "hostname,":

如何在运行ansible playbook时缩小范围?

  • `-i`没那么有用,因为你的组'group1`会迷路.但是`-l server1`或`--limit server1`是要走的路,是的. (4认同)