Dear Experts,
How to launch multiple EC2 instances using ansible?
I want to create an environment in AWS using below playbook but I see only
one instance is being created when I execute below playbook.
Could you please help with missing code/syntax here?
Note: I'm using free account with AWS.
---
- name: Create sandbox instances
hosts: localhost
gather_facts: True
vars:
aws_access_key: aabbccddeeffgghh
aws_secret_key: aabbccddeeffgghhiijjkkllmmnnoopp
key_name: mykeypair
count: 5
exact_count: 'count_tag'
instance_type: 't2.micro'
security_group: my_securitygroup
group: default
image: ami-00125160
ec2_url: https://ec2.us-west-2.amazonaws.com
tasks:
- name: Launch instance
ec2:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
key_name: "{{ key_name }}"
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
count_tag: "{{ exact_count }}"
image: "{{ image }}"
wait: true
ec2_url: "{{ ec2_url }}"
vpc_subnet_id: subnet-edcf00db
assign_public_ip: yes
register: ec2
- name: Add new instance to host group
add_host:
hostname: "{{ item.public_ip }}"
groupname: launched
with_items: "{{ ec2.instances }}"
- name: Wait for SSH to come up
wait_for:
host: "{{ item.public_dns_name }}"
port: 22
delay: 60
timeout: 320
state: started
with_items: "{{ ec2.instances }}"
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/51b431bb-e0dd-4765-9051-cf5dbc8d624c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.