簡體   English   中英

使用Ansible創建AWS目標組

[英]Creating an aws target group with ansible

我試圖完成的任務是從動態生成的實例列表創建網絡負載平衡器目標組。

brokerInstancesList是實例ID的列表。 我需要遍歷此列表,並將它們作為目標添加到該目標組。

- 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 }}"

我上面嘗試的問題在於,僅保留brokerInstancesList中的最后一個條目。 我需要以下類似的東西。

- 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_target_group任務中將target_data列表用作targets屬性。

來源: https : //github.com/ansible/ansible/issues/32218#issuecomment-339792059

使用elb_target模塊來實現它:

  • 名稱:收集所有新代理實例的事實
    ec2_instance_facts:
    篩選器:
    “ tag:Name”:“ {{ec2_tag_proxy}}”
    注冊:ec2_proxy

  • elb_target_group:
    名稱:uat-target-proxy
    通訊協定:http
    端口:80
    vpc_id:vpc-4e6e8112
    deregistration_delay_timeout:60
    stickiness_enabled:真
    stickiness_lb_cookie_duration:86400
    health_check_path:/
    success_response_codes:“ 200”
    health_check_interval:“ 20”
    狀態:存在

  • elb_target:
    target_group_name:uat-target-proxy
    target_id:“ {{item.instance_id}}”
    target_port:80
    狀態:存在
    with_items:“ {{ec2_proxy.instances}}”
    時間:ec2_proxy.instances | length> 0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM