Amazon web services 使用ansible创建aws目标群
我试图完成的是从动态生成的实例列表中创建一个网络负载平衡器目标组 BrokerInstanceList是实例ID的列表。我需要遍历这个列表,并将它们作为目标添加到此目标组Amazon web services 使用ansible创建aws目标群,amazon-web-services,loops,ansible,Amazon Web Services,Loops,Ansible,我试图完成的是从动态生成的实例列表中创建一个网络负载平衡器目标组 BrokerInstanceList是实例ID的列表。我需要遍历这个列表,并将它们作为目标添加到此目标组 - name: "Create 9092 target group" elb_target_group: name: "tg-{{ ClusterName }}" protocol: tcp port: 9092 vpc_id: "{{ VPCID }}" targets:
- name: "Create 9092 target group"
elb_target_group:
name: "tg-{{ ClusterName }}"
protocol: tcp
port: 9092
vpc_id: "{{ VPCID }}"
targets:
- Id: "{{ item }}"
Port: 9092
state: present
loop: "{{ brokerInstancesList }}"
我上面尝试的问题是只保留BrokerInstanceList中的最后一个条目。像下面这样的东西是我需要的
- name: "Create 9092 target group"
elb_target_group:
name: "tg-{{ ClusterName }}"
protocol: tcp
port: 9092
vpc_id: "{{ VPCID }}"
targets:
{% for item in {{ brokerInstancesList }} -%}
- Id: "{{ apple }}"
Port: 9092
{%- endfor %}
state: present
您需要在上一步中创建目标列表:
- name: Create the custom fact for targets
set_fact:
target_data: "{{ target_data|default([]) + [{'Id': item, 'Port': 9092 }]}}"
with_items: "{{ brokerInstancesList }}"
然后使用elb\u target\u组
任务中的targets
属性的target\u数据
列表
来源:使用elb_目标模块来实现它:
- 名称:收集所有新代理实例的事实
ec2_实例_事实:
过滤器:
“tag:Name”:“{ec2_tag_proxy}}”
注册:ec2_代理 - elb_目标群体:
名称:uat目标代理
协议:http
端口:80
专有网络id:vpc-4e6e8112
注销\u延迟\u超时:60
粘性启用:真
粘性\u磅\u饼干\u持续时间:86400
运行状况检查路径:/
成功响应代码:“200”
健康检查间隔:“20”
国家:现在 - elb_目标:
目标\组\名称:uat目标代理
target_id:“{{item.instance_id}}”
目标端口:80
状态:当前
带_项:“{ec2_proxy.instances}}”
当:ec2_proxy.instances | length>0