いくつかのドキュメントを調べた後、with_items
forは使用できないと結論付けましたroles
。
そこで、filter_plugin
役割の辞書のリストを生成する を作成しました。
これが私のものPlay
です:
---
- name: Boostrap vpc and subnets with route table
hosts: localhost
connection: local
gather_facts: no
pre_tasks:
- include_vars: ec2_vars/common/regions.yml
- include_vars: environment.yml
roles:
- {
role: vpc,
ec2_region: 'ap-southeast-2'
}
- {
role: vpc,
ec2_region: "ap-southeast-1",
}
- {
role: vpc,
ec2_region: "us-west-2",
}
上記のロールを動的に生成したいのでfilter_plugin
、辞書のリストを生成する を作成しましたが、それは正しく機能しています。
これが私のプラグインです:
# this is for generating vpc roles
def roles(ec2_regions):
return [{'role': 'vpc', 'ec2_region': ec2_region} for ec2_region in ec2_regions]
class FilterModule(object):
def filters(self):
return {'vpcroles': roles}
私の計画は、次のような役割を生成することでした:
roles: "{{ EC2_REGIONS | vpcroles }}"
どこEC2_REGIONS
ですか['ap-southeast-2', 'us-east-1']
しかし、役割はそのようには機能しません。
次のエラーが表示されます:
ERROR! A malformed role declaration was encountered.
何か考え/アイデアはありますか?