-
Notifications
You must be signed in to change notification settings - Fork 2
/
aws_swarm_master.yml
56 lines (49 loc) · 1.64 KB
/
aws_swarm_master.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
- name: Provision a Swarm v2 master on AWS
hosts: localhost
connection: local
gather_facts: False
tasks:
- name: Find the latest Ubuntu Wily image
ec2_ami_find:
region: us-east-1
name: "ubuntu/images/hvm/ubuntu-wily-15.10-amd64-server-*"
sort: name
sort_order: descending
sort_end: 1
register: ami_find
- name: Create the EC2 instance
ec2:
image: "{{ ami_find.results[0].ami_id }}"
region: us-east-1
instance_type: t2.medium
key_name: swarm
group: dockermachine
wait: yes
register: ec2
- name: wait for ssh server to be running
wait_for: host={{ item.public_dns_name }} port=22 search_regex=OpenSSH delay=60
with_items: "{{ ec2.instances }}"
when: item.public_dns_name is defined
- name: Provision a Docker Host with machine
docker_machine:
provider: "generic"
name: "swarm-master-{{ item.public_dns_name }}"
ip_address: "{{ item.public_ip }}"
ssh_key: "~/.aws/keys/swarm.pem"
ssh_user: "ubuntu"
with_items: "{{ ec2.instances }}"
register: machine_result
- shell: >
eval $(docker-machine env swarm-master-"{{ item.public_dns_name }}")
echo $DOCKER_TLS_VERIFY &&
echo $DOCKER_HOST &&
echo $DOCKER_CERT_PATH &&
echo $DOCKER_MACHINE_NAME
with_items: "{{ ec2.instances }}"
register: master
- set_fact:
dhost: "{{ master.stdout_lines[0] }}"
dcert: "{{ master.stdout_lines[1] }}"
dmach: "{{ master.stdout_lines[2] }}"
- debug: msg="{{ dhost }}" "{{ dcert }}" "{{ dmach }}"