0
我正在嘗試使用Ansible提供多個AWS EC2計算機。我想使「availabilityZone」和「tag_name」爲動態。請找到下面的任務。如果我將計數更改爲2,我應該可以在不做任何修改的情況下運行相同的任務來創建兩個實例。使用Ansible提供多個EC2實例
- name: Provision an instance
ec2:
key_name: "{{ keyPairName }}"
instance_type: m3.medium
image: "{{ amiId }}"
region: us-east-1
zone: us-east-1{{ item.0 }}
group_id: "{{ securityGroup }}"
vpc_subnet_id: "{{ subnet }}"
wait: true
count: 1
instance_tags:
Name: esl-master{{ item.1 }}-{{ deployenv }}
register: ec2_master
with_together:
- [ 'a', 'b', 'c' ]
- [ 1, 2, 3 ]
when: isMaster
通過上面的配置,我得到了下面的錯誤。
failed: [localhost] (item=[u'b', 2]) => {"failed": true, "item": ["b", 2], "msg": "Instance creation failed => InvalidParameterValue: Value (us-east-1b) for parameter availabilityZone is invalid. Subnet 'subnet-f22551d9' is in the availability zone us-east-1a"}
failed: [localhost] (item=[u'c', 3]) => {"failed": true, "item": ["c", 3], "msg": "Instance creation failed => InvalidParameterValue: Value (us-east-1c) for parameter availabilityZone is invalid. Subnet 'subnet-f22551d9' is in the availability zone us-east-1a"}
有沒有更好的方法做到這一點,因爲我想利用'Zone'參數?
謝謝你的回覆。在我的情況下,我只有一個子網ID – Vinil
[每個子網必須完全位於一個可用區內,不能跨區域。](https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html) - - 你能決定你想要什麼嗎? – techraf
我所希望的是將所有區域和子網信息作爲列表或逗號分隔值傳遞。看起來這個選項不存在。我將不得不經過一個序列。謝謝 – Vinil