Created
January 3, 2017 14:03
-
-
Save bbenson29/de0ccf7eb3160590275f60e83e796590 to your computer and use it in GitHub Desktop.
Provision ec2 instance with ansible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - hosts: localhost | |
| connection: local | |
| gather_facts: true | |
| become: true | |
| vars_files: | |
| - vars.yml | |
| tasks: | |
| - name: Launch ec2 on aws | |
| ec2: | |
| access_key="{{ ec2_access_key }}" | |
| secret_key="{{ ec2_secret_key }}" | |
| keypair="{{ ec2_keypair }}" | |
| image="{{ ec2_image }}" | |
| type="{{ ec2_type }}" | |
| region={{ ec2_region }} | |
| instance_tags="{'Name':'{{ ec2_tag }}'}" | |
| count_tag="{'Name':'{{ ec2_tag }}'}" | |
| exact_count="{{ ec2_instance_count }}" | |
| wait=true | |
| register: ec2 | |
| - name: Add new instance to the local host group | |
| local_action: lineinfile dest=hosts regexp="{{ item.public_dns_name }}" insertafter="[launched]" line="{{ item.public_dns_name }} ansible_ssh_private_key_file=/Users/$USER/.ssh/"{{ ssh_key }}"" | |
| with_items: "{{ ec2.instances }}" | |
| - name: Wait for instance to come up | |
| local_action: wait_for host={{ item.public_dns_name }} | |
| port={{ wait_for_port }} delay=180 timeout=320 state=started | |
| with_items: "{{ ec2.instances }}" | |
| hosts file | |
| [local] | |
| localhost ansible_python_interpreter=/usr/local/bin/python | |
| [launched] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment