Ansible:在相同变量的情况下

时间:2015-10-09 07:06:34

标签: ansible

我有一个包含相同变量的文件,每个变量属于不同的服务:

#integration/integration.yml

WEB:
aws_id: <some var>
aws_outh: <some var>

BACKEND:
aws_id: <some var>
aws_outh: <some var>

每项服务都有自己的角色/任务:

roles/web
roles/backend

如何为每个服务创建ansible任务,指向它所属的变量?

1 个答案:

答案 0 :(得分:0)

如果您在respectiv角色中使用变量awd_idaws_outh,则可以执行以下操作:

#integration/integration.yml

# indent the aws* variables to make them keys in the dictornary WEB and BACKEND
WEB:
  aws_id: <some var>
  aws_outh: <some var>

BACKEND:
  aws_id: <some var>
  aws_outh: <some var>

在你的剧本中:

# ...
roles:
  - { role: web, aws_id: "{{ WEB.aws_id }}", aws_outh: "{{ WEB.aws_outh }}" }
  - { role: backend, aws_id: "{{ BACKEND.aws_id }}", aws_outh: "{{ BACKEND.aws_outh }}" }