-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathlaunch_jenkins.yml
57 lines (43 loc) · 1.54 KB
/
launch_jenkins.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
---
- name: "launch jenkins"
hosts: localhost
gather_facts: no
vars:
aws_region: us-west-2 # If not specified then the value of the EC2_REGION environment variable, if any, is used.
keyname: jenkins_access
instance_type: t2.medium
linux_ami: ami-e7527ed7
security_group: jenkins
ami_profile: jenkins
iam_role: jenkinsRole
# vpc_id: and subnet_public: added to group_vars/all by script 'setup_vpc_subnets.yml' at runtime
tasks:
- name: Launch jenkins instance
ec2:
key_name: "{{ keyname }}"
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
instance_profile_name: "{{ iam_role }}"
image: "{{ linux_ami }}"
wait: true
region: "{{ aws_region }}"
vpc_subnet_id: "{{ subnet_public }}"
assign_public_ip: yes
instance_tags:
Name: "jenkins_main"
register: ec2
- name: Add new instance to host group
add_host: hostname={{ item.public_ip }} groupname=launched ansible_ssh_user=ec2-user ansible_ssh_private_key_file="jenkins_access.pem"
with_items: ec2.instances
- name: Wait for SSH to come up
local_action: wait_for host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started
with_items: ec2.instances
- name: Configure Jenkins instance(s)
hosts: launched
sudo: True
user: ec2-user
gather_facts: True
roles:
- { role: base, ami_profile: jenkins }
- { role: jenkins, ami_profile: jenkins }
- { role: postrun, ami_profile: jenkins }