【发布时间】:2018-04-27 16:04:30
【问题描述】:
我正在尝试使用 ansible 来管理远程 postgres 实例的角色,其剧本如下所示:
---
- hosts: localhost
tasks:
- postgresql_user:
login_host: the.db.com
login_password: password
port: 5432
login_user: admin
db: the-db
name: user-i-want-to-create
这可行,但我想创建很多这样的用户,并且为每个用户一遍又一遍地重复 5 个参数是乏味且容易出错的。我怎样才能将这些变量分解为不需要为每个任务重复它们?
【问题讨论】:
-
我遇到了类似的问题,当时 Ansible 的回答是“这不是 Ansible 的设计初衷”。不确定过去一年情况是否发生了变化。
-
您有没有费心查看 Ansible 文档?谷歌
ansible loops. -
@techraf 我有,但没想到专门搜索循环。不过,它们似乎很有希望,如果不是我想要的。 (他们仍然需要为不同的 postgres 相关结构重复连接信息,例如)。