2017-09-27 37 views
1

中的每個新的次級私用IP,我試圖將多個彈性IP分配給多個不同的私有IP地址。Ansible:將多個EIP分配給ENI

注意:IP地址是假的,我已經這樣寫過,以便讓您明白我想要做什麼。

這是我迄今取得:

Server 1 

    Elastic Network Interface 
    Private IP 172.x.x.1 (public IP: 55.x.x.1) 
    Secondary Private IP 
     172.x.x.2 (public IP: NONE SET) 
     172.x.x.3 (public IP: NONE SET) 

Server 2 

    Elastic Network Interface 
    Private IP 174.x.x.1 (public IP: 57.x.x.1) 
    Secondary Private IP 
     174.x.x.2 (public IP: NONE SET) 
     174.x.x.3 (public IP: NONE SET) 

這就是我想實現:

Server 1 

    Elastic Network Interface 
    Private IP 172.x.x.1 (public IP: 55.x.x.1) 
    Secondary Private IP 
     172.x.x.2 (public IP: 55.x.x.2) 
     172.x.x.3 (public IP: 55.x.x.3) 

Server 2 

    Elastic Network Interface 
    Private IP 174.x.x.1 (public IP: 57.x.x.1) 
    Secondary Private IP 
     174.x.x.2 (public IP: 57.x.x.2) 
     174.x.x.3 (public IP: 57.x.x.3) 

這裏的Ansible劇本我寫到目前爲止:

{{ platform }}是通過CLI傳遞的額外的變量。

- name: Provision a set of Edge instances 
    ec2: 
    key_name: ec2user 
    group: "launch-wizard-1" 
    instance_type: "m4.2xlarge" 
    image: "ami-xxxxxxx" 
    region: "eu-west-1" 
    wait: true 
    exact_count: 2 
    count_tag: 
     PlatformName: "{{ platform }}" 
     Role: Edge 
    instance_tags: 
     Name: "{{ platform }}::Edge" 
     PlatformName: "{{ platform }}" 
     Role: Edge 
     LongName: "Edge server for {{ platform }}'s platform" 
     Groups: common,server,rabbitmq,memcache,stats,cache-manager,media,content,icecast 
    register: edge_ec2 

- name: Find ENIs created for Edge instances 
    ec2_eni_facts: 
    region: "eu-west-1" 
    filters: 
     attachment.instance-id: "{{ item }}" 
    with_items: "{{ edge_ec2.instance_ids }}" 
    register: edge_enis 

- name: Adds an additional private IP to the Edge ENIs 
    ec2_eni: 
    region: "eu-west-1" 
    eni_id: "{{ item.interfaces[0].id }}" 
    subnet_id: "{{ item.interfaces[0].subnet_id }}" 
    state: present 
    secondary_private_ip_address_count: 2 
    register: created_ips 
    with_items: "{{ edge_enis.results }}" 

- name: Adds additional elastic IPs to the Edge ENIs 
    ec2_eip: 
    device_id: "{{ item.0.interface.attachment.instance_id }}" 
    region: "eu-west-1" 
    private_ip_address: "{{ item.1.private_ip_address }}" 
    in_vpc: true 
    register: eips 
    with_subelements: 
    - "{{ created_ips.results }}" 
    - interface.private_ip_addresses 

爲什麼不ansible分配新分配的IP彈性與次級私有IP地址,但僅限於主之一,即使我明確告訴它分配給次級私有地址?

+0

在您的帖子中找不到任何問題。 – ceving

+0

增加了這個問題,對此感到遺憾 – GiamPy

回答

0

我不知道爲什麼Ansible ec2_eip模塊無法創建新的彈性IP並將其分配給指定的輔助私有IP地址,但我確實發現了一種解決方法。

我遇到了同樣的問題 - 在我看來,private_ip_address選項被忽略。下面是我的代碼片段沒有工作:

- name: try to create an EIP and associate it in one pass 
    ec2_eip: 
    device_id: "{{ item.network_interfaces[0].network_interface_id }}" 
    private_ip_address: "{{ item.network_interfaces[0].private_ip_addresses[1].private_ip_address }}" 
    region: ap-southeast-2 
    in_vpc: true 
    with_items: "{{ servers.results[0].instances }}" 

我的解決方法是預先創建的彈性IP地址,然後將它們與一個單獨的任務私有IP地址相關聯。

- name: "allocate a new elastic IP for each server without associating it with anything" 
    ec2_eip: 
    state: 'present' 
    region: ap-southeast-2 
    register: eip2 
    with_items: "{{ servers.results[0].instances }}" 

- name: Associate elastic IPs with the first interface attached to each instance 
    ec2_eip: 
    public_ip: "{{ eip2.results[item.0].public_ip }}" 
    device_id: "{{ item.1.network_interfaces[0].network_interface_id }}" 
    private_ip_address: "{{ item.1.network_interfaces[0].private_ip_addresses[1].private_ip_address }}" 
    region: ap-southeast-2 
    in_vpc: true 
    with_indexed_items: "{{ servers.results[0].instances }}" 

我的主要發現是,如果你提供public_ip那麼private_ip_address選項開始被認可。