-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathami_master.yml
137 lines (133 loc) · 3.7 KB
/
ami_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
- name: Create Instance
hosts: localhost
gather_facts: false
tags:
- create
tasks:
- name: Include variables
include_vars: all.yml
- name: Create instance
ec2:
region: "{{ vpc_region }}"
vpc_subnet_id: "{{ vpc_kubernetes_subnets[0].id }}"
key_name: "{{ ec2_keypair }}"
instance_type: t2.micro
image: "{{ source_ami }}"
count_tag:
role: ami_build_master
exact_count: 1
instance_tags:
os: coreos
role: ami_build_master
wait: true
- name: Refresh Inventory
meta: refresh_inventory
- name: Bootstrap Instance
include: bootstrap_coreos.yml
vars:
hosts: tag_role_ami_build_master
tags:
- bootstrap
- name: Provision Instance
hosts: tag_role_ami_build_master
gather_facts: true
become: true
tags:
- provision
tasks:
- name: Include variables
include_vars: all.yml
- name: /opt/bin is present
file:
dest: /opt/bin
state: directory
- name: cfssl binaries are present
get_url:
url: "{{ item.url }}"
dest: /opt/bin/{{ item.name }}
mode: 0755
with_items:
- name: cfssl
url: "https://pkg.cfssl.org/{{cfssl_version}}/cfssl_linux-amd64"
- name: cfssljson
url: "https://pkg.cfssl.org/{{cfssl_version}}/cfssljson_linux-amd64"
- name: /etc/certfetcher directory is present
file:
dest: /etc/certfetcher
state: directory
- name: certfetcher CSRs are present
template:
src: certfetcher/{{ item }}
dest: /etc/certfetcher/{{ item }}
with_items:
- worker-csr.json
- master-csr.json
- name: certfetcher service is present
template:
src: certfetcher/certfetcher.service
dest: /etc/systemd/system/
# Cloud init
- name: Custom cloud config directory is present
file:
dest: /var/lib/coreos-install
state: directory
- name: Custom cloud config file is present
template:
src: cloud_config/master
dest: /var/lib/coreos-install/user_data
register: cloud_config_file
- name: Kubernetes directories are present
file:
dest: "{{ item }}"
state: directory
with_items:
- /etc/kubernetes
- /etc/kubernetes/manifests
- /etc/kubernetes/cni
- /etc/kubernetes/cni/net.d
- name: service account key is present
copy:
src: service-account.pem
dest: /etc/kubernetes/service-account.pem
- name: kubeconfigs are present
template:
src: "{{ item }}"
dest: /etc/kubernetes/
with_items:
- worker-kubeconfig.yml
- master-kubeconfig.yml
- name: kubelet service is present
template:
src: kubelet.service
dest: /etc/systemd/system/kubelet.service
- name: Kubernetes master components are present
template:
src: manifests/{{ item }}
dest: /etc/kubernetes/manifests/{{ item }}
with_items:
- kube-apiserver.yml
- kube-proxy.yml
- kube-controller-manager.yml
- kube-scheduler.yml
- name: Create AMI
hosts: localhost
gather_facts: false
tags:
- ami
vars:
output: {}
tasks:
- name: Include variables
include_vars: all.yml
- name: Create AMI
ec2_ami:
region: "{{ vpc_region }}"
instance_id: "{{ hostvars[groups['tag_role_ami_build_master'][0]]['ec2_id'] }}"
wait: yes
name: "{{ master_ami_name }}"
register: ami_out
- name: AMI id is set in output
set_fact:
output: "{{ output | combine({'master_ami_id': ami_out.image_id }) }}"
- name: Variables are printed
debug: var=output