├── .gitignore ├── LICENSE ├── README.md ├── defaults └── main.yml ├── meta └── main.yml └── tasks └── main.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | ._* 3 | .Spotlight-V100 4 | .Trashes 5 | test -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Crush & Lovely, Pablo Castillo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Role For EC2 Provisioning 2 | 3 | [![Current Version](http://img.shields.io/github/release/crushlovely/ansible-ec2-provision.svg?style=flat)](https://crushlovely/ansible-ec2-provision/releases) 4 | 5 | Provions ec2 instances. This role provisions instances inside of a EC2 VPC it has not been tested to provision instances inside of an EC2 classic network. 6 | 7 | ## Installation 8 | 9 | ``` bash 10 | $ ansible-galaxy install crushlovely.ec2_provision,v1.0.0 11 | ``` 12 | 13 | ## Variables 14 | 15 | You will want to fill all these in before running the role. 16 | 17 | ``` yaml 18 | aws: 19 | ec2_access_key: "Amazon IAM access key" 20 | ec2_secret_key: "Aamazon secret key" 21 | keypair: "Amazon security key pair" 22 | image: "Image to be provisioned" 23 | acct_vpc_id: "EC2 vpc id" 24 | region: "us-east-1" 25 | group: "{{ app_name }}-{{ server_env }}" 26 | instance_type: "m3.medium" 27 | quantity: "1" 28 | vpc_subnet: "EC2 VPC regional subnet" 29 | app_name: test 30 | server_env: qa 31 | ``` 32 | You can also add a vars folder to your project folder and have your variables served by adding them to a file and calling it in your playbook. 33 | 34 | ```yaml 35 | - hosts: localhost 36 | ... 37 | vars_files: 38 | - vars/default_vars.yml 39 | ... 40 | ``` 41 | 42 | 43 | ## Usage 44 | 45 | Once this role is installed on your system, include it in the roles list of your playbook. 46 | 47 | ``` yaml 48 | - hosts: localhost 49 | connection: local 50 | gather_facts: True 51 | roles: 52 | - { role: crushlovely.ec2_provision, zone: "", vpc_subnet: "" } 53 | ``` 54 | 55 | ## Dependencies 56 | 57 | Although, this role is not dependant on ec2_group it is highly recommended that the ec2_group role is also added to your playbook to ensure ec2 tags match. Boto is required to use this role. 58 | 59 | ## License 60 | 61 | MIT -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | aws_access_key: "" 3 | aws_secret_key: "" 4 | aws_acct_vpc_id: "" 5 | aws_group: "{{ app_name }}-{{ server_env }}" 6 | aws_instance_type: "" 7 | aws_quantity: "" 8 | aws_region: "us-east-1" 9 | aws_vpc_subnet: "" 10 | aws_image: "" 11 | aws_keypair: "" 12 | aws_instance_tag: '{"Name":"{{ app_name }}_{{ server_env }}_","Group1":"{{ app_name }}_{{ server_env }}","Group2":"{{ app_name }}_{{ server_env }}_"}' 13 | app_name: test 14 | server_env: qa 15 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Pablo Castillo 4 | company: Crush & Lovely 5 | description: Provision EC2 instance 6 | license: MIT 7 | min_ansible_version: 1.9 8 | platforms: 9 | - name: Ubuntu 10 | versions: 11 | - all 12 | categories: 13 | - cloud 14 | dependencies: [] 15 | version: 4.0.0 16 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: make one instance 3 | local_action: 4 | module: ec2 5 | image: "{{ aws_image }}" 6 | instance_type: "{{ aws_instance_type }}" 7 | aws_access_key: "{{ aws_access_key }}" 8 | aws_secret_key: "{{ aws_secret_key }}" 9 | keypair: "{{ aws_keypair }}" 10 | count: "{{ aws_quantity }}" 11 | instance_tags: "{{ aws_instance_tag }}" 12 | region: "{{ aws_region }}" 13 | group: "{{ aws_group }}" 14 | vpc_subnet_id: "{{ aws_vpc_subnet }}" 15 | wait: true 16 | register: ec2_info 17 | 18 | - debug: var=ec2_info 19 | - debug: var=item 20 | with_items: ec2_info.instance_ids 21 | 22 | - add_host: hostname={{ item.public_ip }} groupname={{ app_name }}_{{ server_env }} 23 | with_items: ec2_info.instances 24 | 25 | - name: wait for instances to listen on port:22 26 | wait_for: 27 | state: started 28 | host: "{{ item.public_dns_name }}" 29 | port: 22 30 | with_items: ec2_info.instances 31 | --------------------------------------------------------------------------------