Skip to content

Instantly share code, notes, and snippets.

@tuudik
Created December 13, 2018 20:36
Show Gist options
  • Save tuudik/95052492b6e23d110bcd5e267a3b5dd5 to your computer and use it in GitHub Desktop.
Save tuudik/95052492b6e23d110bcd5e267a3b5dd5 to your computer and use it in GitHub Desktop.
- name: "Provision EC2 instaces"
ec2:
key_name: "{{ ec2_keypair }}"
group: "{{ item.ec2_security_group }}"
instance_type: "{{ item.ec2_instance_type }}"
image: "{{ ami_data.results[0].ami_id }}"
region: "{{ vpc_region }}"
instance_tags: '{"Name":"{{item.ec2_host_name}}.{{subdomain}}.{{domain}}.{{item.ec2_tld | default(internal_tld)}}","Role":"{{item.ec2_host_role}}","Environment":"{{ vpc_name }}","Host Name":"{{item.ec2_host_name}}.{{subdomain}}.{{domain}}.{{internal_tld}}"}'
count_tag: '{"Name":"{{item.ec2_host_name}}.{{subdomain}}.{{domain}}.{{item.ec2_tld | default(internal_tld)}}","Role":"{{item.ec2_host_role}}","Environment":"{{ vpc_name }}","Host Name":"{{item.ec2_host_name}}.{{subdomain}}.{{domain}}.{{internal_tld}}"}'
assign_public_ip: "{{ item.ec2_public_ip | default('false') }}"
vpc_subnet_id: "{{ item.ec2_vpc_subnet_id }}"
wait: true
exact_count: 1
volumes:
- device_name: "{{ item.ec2_device_name }}"
volume_type: "{{ item.ec2_device_volume_type }}"
volume_size: "{{ item.ec2_volume_size }}"
delete_on_termination: "{{ item.ec2_delete_on_termination }}"
user_data: |
#cloud-config
fqdn: {{item.ec2_host_name}}.{{subdomain}}.{{domain}}.{{ internal_tld}}
manage_etc_hosts: true
with_items: "{{ ec2_instances }}"
register: ec2_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment