Ansible将服务器集合成'应用程序'

时间:2015-06-30 17:40:03

标签: ansible

我有一个设置所有服务器的脚本。现在试图找出一种配置它们以便彼此交谈的好方法。例如配置应用程序服务器以与特定数据库服务器通信。

  • 测试应用1
    • DB01
    • app01
    • app02
    • mem01
  • 测试应用2
    • DB02
    • app03
    • mem02

我唯一可以想出一个将服务器作为params的角色,但我不喜欢我还必须指定主机两次。

- name: Test app 1
  hosts: [db01, app01, app02, mem01]
  roles:
    - {role: app, db: db01, ap: [app01, app02], mem: mem01}

1 个答案:

答案 0 :(得分:0)

inventory file

的整理程度如何?

查看您发布的内容,这可能是一个很好的库存文件组织:

[testapp1-dbServers]
db01

[testapp1-appServers]
app01
app02

[testapp1-memServers]
mem01

[testapp2-dbServers]
db02

[testapp2-appServers]
app03

[testapp2-memServers]
mem02

[testapp1:children]
testapp1-dbServers
testapp1-appServers
testapp1-memServers

[testapp2:children]
testapp2-dbServers
testapp2-appServers
testapp2-memServers

[dbServers:children]
testapp1-dbServers
testapp2-dbServers

[appServers:children]
testapp1-appServers
testapp2-appServers

[memServers:children]
testapp1-memServers
testapp2-memServers

如果您没有计划增加前6个存储桶中任何一个服务器的数量,这可能会有点过分,但是它允许您执行诸如group_vars文件之类的操作(对于某些或所有分组来说都是个别的 - testapp1,testapp2,dbServers等等)并清理你的剧本文件:

- name: Test app 1
  hosts: testapp1 (all vars passed via group_vars file)
  roles:
    - generic_server_setup

- name: DB Server setup
  hosts: dbServers (all vars passed via group_vars file)
  roles:
    - install_postgres
    - other_db_things

here可以找到最能帮到你的东西。

具体来说,访问当前主机所在的所有组以及组中的所有主机。

快速修复:如果您想牺牲一些组织,因为您不担心扩展并且不会被多个位置的相同信息所困扰,只需将相关主机作为vars添加到group_vars下的testapp1和testapp2文件。 / p>

相关问题