【问题标题】:Pointing to a specific host under a group, Ansible指向组下的特定主机,Ansible
【发布时间】:2017-01-19 14:40:49
【问题描述】:

我的 Ansible 主机文件中的一个组下有多个主机详细信息。如下所示,

[web-server]
10.0.0.1 name=apache ansible_ssh_user=username
10.0.0.2 name=nginx ansible_ssh_user=username 

我的 ansible 剧本,

---
  - hosts: web-server[0]
    roles:
      - role: apache

这些详细信息会动态添加到主机文件中,我无法控制在组下添加行的顺序。因此我不能使用逻辑 web-server[0] 或 web-server[1]

我想通过基于剧本中的“名称”参数过滤来提及主机,因为名称将是唯一的。有没有办法做到这一点,请帮忙。

【问题讨论】:

  • 您不能为您的 apache 和 nginx 服务器创建新组吗?

标签: ansible ansible-playbook ansible-2.x ansible-inventory


【解决方案1】:

如果您可以修改库存文件生成过程,则如下所示:

[web-server]
apache ansible_host=10.0.0.1 ansible_ssh_user=username
nginx ansible_host=10.0.0.2 ansible_ssh_user=username

然后使用:

- hosts: apache

【讨论】:

  • 如果我有多个具有相同主机名的组怎么办?在那种情况下,方法是什么?
  • @shwetha 取决于您的任务。通常主机名是无意义的,组名有功能名,你用组名来打游戏。因此,在不同的组中拥有一个主机不是问题。
猜你喜欢
  • 2017-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-09
  • 2019-11-15
相关资源
最近更新 更多