ansible-roles/amazon-ec2/tasks/create-instance.yml
Mathieu Trossevin 26eec48954
[Cleanup] amazon-ec2, apache, bind, evolinux-todo, evomaintenance
Don't compare with empty string

Name all tasks

Variables should have space before and after their name
2020-12-23 15:06:41 +01:00

37 lines
1 KiB
YAML

---
- name: Launch new instance(s)
ec2:
state: present
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
region: "{{ aws_region }}"
image: "{{ ec2_base_ami }}"
instance_type: "{{ ec2_instance_type }}"
count: "{{ ec2_instance_count }}"
assign_public_ip: "{{ ec2_public_ip }}"
group: "{{ ec2_security_group.name }}"
key_name: "{{ ec2_keyname }}"
wait: yes
register: ec2
- name: Add newly created instance(s) to inventory
add_host:
hostname: "{{ item.public_dns_name }}"
groupname: launched-instances
ansible_user: admin
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
with_items: "{{ ec2.instances }}"
- debug:
msg: "Your newly created instance is reachable at: {{ item.public_dns_name }}"
with_items: "{{ ec2.instances }}"
- name: Wait for SSH to come up on all instances (give up after 2m)
wait_for:
state: started
host: "{{ item.public_dns_name }}"
port: 22
timeout: 120
with_items: "{{ ec2.instances }}"