This commit is contained in:
PC 2017-04-04 14:26:07 +00:00 committed by GitHub
commit 401c6d6b68
2 changed files with 73 additions and 52 deletions

111
algo
View file

@ -208,59 +208,70 @@ EXTRA_VARS="do_access_token=$do_access_token do_server_name=$do_server_name do_r
} }
ec2 () { ec2 () {
read -p " if [[ -z $AWS_ACCESS_KEY_ID ]]; then
Enter your aws_access_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) read -p "
Note: Make sure to use either your root key (recommended) or an IAM user with an acceptable policy attached Enter your aws_access_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html)
[pasted values will not be displayed] Note: Make sure to use either your root key (recommended) or an IAM user with an acceptable policy attached
[AKIA...]: " -rs aws_access_key [pasted values will not be displayed]
[AKIA...]: " -rs aws_access_key
else
aws_access_key=$AWS_ACCESS_KEY_ID
fi
if [[ -z $AWS_SECRET_ACCESS_KEY ]]; then
read -p "
Enter your aws_secret_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html)
Note: Make sure to use either your root key (recommended) or an IAM user with an acceptable policy attached
[pasted values will not be displayed]
[ABCD...]: " -rs aws_secret_key
else
aws_secret_key=$AWS_SECRET_ACCESS_KEY
fi
read -p " read -p "
Enter your aws_secret_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) Name the vpn server:
Note: Make sure to use either your root key (recommended) or an IAM user with an acceptable policy attached [algo]: " -r aws_server_name
[pasted values will not be displayed] aws_server_name=${aws_server_name:-algo}
[ABCD...]: " -rs aws_secret_key
read -p " if [[ -z $AWS_DEFAULT_REGION ]]; then
Name the vpn server: read -p "
[algo]: " -r aws_server_name What region should the server be located in?
aws_server_name=${aws_server_name:-algo} 1. us-east-1 US East (N. Virginia)
2. us-east-2 US East (Ohio)
read -p " 3. us-west-1 US West (N. California)
What region should the server be located in? 4. us-west-2 US West (Oregon)
1. us-east-1 US East (N. Virginia) 5. ap-south-1 Asia Pacific (Mumbai)
2. us-east-2 US East (Ohio) 6. ap-northeast-2 Asia Pacific (Seoul)
3. us-west-1 US West (N. California) 7. ap-southeast-1 Asia Pacific (Singapore)
4. us-west-2 US West (Oregon) 8. ap-southeast-2 Asia Pacific (Sydney)
5. ap-south-1 Asia Pacific (Mumbai) 9. ap-northeast-1 Asia Pacific (Tokyo)
6. ap-northeast-2 Asia Pacific (Seoul) 10. eu-central-1 EU (Frankfurt)
7. ap-southeast-1 Asia Pacific (Singapore) 11. eu-west-1 EU (Ireland)
8. ap-southeast-2 Asia Pacific (Sydney) 12. eu-west-2 EU (London)
9. ap-northeast-1 Asia Pacific (Tokyo) 13. sa-east-1 South America (São Paulo)
10. eu-central-1 EU (Frankfurt) 14. ca-central-1 Canada (Central)
11. eu-west-1 EU (Ireland) Enter the number of your desired region:
12. eu-west-2 EU (London) [1]: " -r aws_region
13. sa-east-1 South America (São Paulo) aws_region=${aws_region:-1}
14. ca-central-1 Canada (Central) case "$aws_region" in
Enter the number of your desired region: 1) region="us-east-1" ;;
[1]: " -r aws_region 2) region="us-east-2" ;;
aws_region=${aws_region:-1} 3) region="us-west-1" ;;
4) region="us-west-2" ;;
case "$aws_region" in 5) region="ap-south-1" ;;
1) region="us-east-1" ;; 6) region="ap-northeast-2" ;;
2) region="us-east-2" ;; 7) region="ap-southeast-1" ;;
3) region="us-west-1" ;; 8) region="ap-southeast-2" ;;
4) region="us-west-2" ;; 9) region="ap-northeast-1" ;;
5) region="ap-south-1" ;; 10) region="eu-central-1" ;;
6) region="ap-northeast-2" ;; 11) region="eu-west-1" ;;
7) region="ap-southeast-1" ;; 12) region="eu-west-2";;
8) region="ap-southeast-2" ;; 13) region="sa-east-1" ;;
9) region="ap-northeast-1" ;; 14) region="ca-central-1" ;;
10) region="eu-central-1" ;; esac
11) region="eu-west-1" ;; else
12) region="eu-west-2";; region=$AWS_DEFAULT_REGION
13) region="sa-east-1" ;; fi
14) region="ca-central-1" ;;
esac
ROLES="ec2 vpn cloud" ROLES="ec2 vpn cloud"
EXTRA_VARS="aws_access_key=$aws_access_key aws_secret_key=$aws_secret_key aws_server_name=$aws_server_name ssh_public_key=$ssh_public_key region=$region" EXTRA_VARS="aws_access_key=$aws_access_key aws_secret_key=$aws_secret_key aws_server_name=$aws_server_name ssh_public_key=$ssh_public_key region=$region"

View file

@ -104,9 +104,19 @@
instance_initiated_shutdown_behavior: terminate instance_initiated_shutdown_behavior: terminate
register: ec2 register: ec2
- name: Allocate and attach a new elastic IP to the instance
ec2_eip:
state: present
region: "{{ region }}"
release_on_disassociation: yes
reuse_existing_ip_allowed: yes
in_vpc: yes
device_id: "{{ ec2.tagged_instances[0].id }}"
register: eip
- name: Add new instance to host group - name: Add new instance to host group
add_host: add_host:
hostname: "{{ item.public_ip }}" hostname: "{{ eip.public_ip }}"
groupname: vpn-host groupname: vpn-host
ansible_ssh_user: ubuntu ansible_ssh_user: ubuntu
ansible_python_interpreter: "/usr/bin/python2.7" ansible_python_interpreter: "/usr/bin/python2.7"
@ -116,7 +126,7 @@
with_items: "{{ ec2.tagged_instances }}" with_items: "{{ ec2.tagged_instances }}"
- set_fact: - set_fact:
cloud_instance_ip: "{{ ec2.tagged_instances[0].public_ip }}" cloud_instance_ip: "{{ eip.public_ip }}"
- name: Get EC2 instances - name: Get EC2 instances
ec2_remote_facts: ec2_remote_facts: