-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_hosts.yaml
63 lines (58 loc) · 1.74 KB
/
create_hosts.yaml
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
57
58
59
60
61
62
63
- hosts: localhost
vars:
ec2_instances:
- name: "jenkins"
image: ""
tags: ['jenkins']
group_id: ''
ssh_user: "ec2-user"
- name: "test"
image: ""
tags: ['test']
ssh_user: "ec2-user"
group_id: ''
- name: "deploy"
image: ""
tags: ['deploy']
ssh_user: "ec2-user"
group_id: ''
tasks:
- name: Launch Instance
ec2:
group_id: "{{ item.group_id }}"
count: 1
instance_type: 't2.micro'
image: '{{ item.image }}'
wait: true
region: 'us-west-2'
#keypair: '{{ keypair }}'
aws_access_key: ""
aws_secret_key: ""
instance_tags: "{{ item.tags }}"
register: ec2
with_items: ec2_instances
- name: Wait for SSH
wait_for:
host: "{{ item['instances'][0]['public_ip'] }}"
port: 22
delay: 10
timeout: 320
state: started
with_items: ec2.results
- name: Wait a little longer for centos
pause: seconds=20
#- name: Copy ssh-key to the guests
#copy: src=~/.ssh/id_rsa dest=~/.ssh/authorized_keys
- name: Add hosts group temporary inventory group with pem path
add_host:
name: "{{ item.1.platform }} {{ ec2.results[item.0]['instances'][0]['public_ip'] }}"
groups: dynamic_hosts
ansible_ssh_host: "{{ ec2.results[item.0]['instances'][0]['public_ip'] }}"
ansible_ssh_private_key_file: '{{ pem_path }}'
ansible_ssh_user: "{{ item.1.ssh_user }}"
ec2_vars: "{{ ec2.results[item.0]['instances'][0] }}"
ec2_instance_ids: "{{ ec2.results[item.0]['instance_ids'] }}"
with_indexed_items: ec2_instances
- hosts: dynamic_hosts
tasks:
- ping: