我有一个包含相同变量的文件,每个变量属于不同的服务:
#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任务,指向它所属的变量?
答案 0 :(得分:0)
如果您在respectiv角色中使用变量awd_id
和aws_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 }}" }