-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_build_cluster.yml
70 lines (62 loc) · 2.43 KB
/
1_build_cluster.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
---
#
# This Playbook provisions a new EKS cluster using eksctl
#
- hosts: localhost
gather_facts: false
vars:
ansible_pyton_interpreter: "{{ ansible_playbook_python }}"
vars_files:
- "vars/{{ env }}.yml"
pre_tasks:
- name: Display Ansible Playbook Python Path.
debug:
msg: "Python Interperter at: {{ ansible_playbook_python }}"
- name: Check if eksctl is installed.
shell: eksctl version
register: eksctl_version
ignore_errors: true
changed_when: false
- name: Install eksctl.
when: "not eksctl_version.rc == 0"
shell: |
set -o pipefail && \
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
mv /tmp/eksctl /usr/local/bin
tasks:
- name: Check if {{ cluster_name }} cluster is running.
shell: eksctl get cluster -o yaml | awk '$2 =="name:" {print $3}'
register: prior_cluster_status_check
ignore_errors: true
changed_when: false
- name: Abort Play. Cluster Exists.
when: "prior_cluster_status_check.stdout == cluster_name"
fail: msg="Cluster {{ cluster_name }} already exists."
- name: "Create Cluster {{ cluster_name }}"
when: "prior_cluster_status_check.stdout != cluster_name"
shell: |
eksctl create cluster --name {{ cluster_name }} \
--region {{ aws_region }} \
--version {{ k8_version }} \
--vpc-cidr {{ vpc_cidr }} \
--managed \
--nodegroup-name {{ nodegroup_name }} \
--nodes {{ node_group_nodes }} \
--nodes-min {{ node_group_nodes_min }} \
--nodes-max {{ node_group_nodes_max }} \
--node-type {{ node_group_nodes_type }} \
--ssh-access=true \
--ssh-public-key={{ node_ssh_key }} \
--external-dns-access \
--alb-ingress-access \
--asg-access \
--tags "Project=Arctiq-Mission,COLOR={{ env }}"
register: cluster_creation_result
- name: Print Cluster Creation Output
when: "prior_cluster_status_check.stdout != cluster_name and cluster_creation_result.rc == 0"
debug:
var: "{{ cluster_creation_result.stdout }}"
- name: Print Cluster Creation Output Errors
when: "prior_cluster_status_check.stdout != cluster_name and cluster_creation_result.rc != 0"
debug:
var: "{{ cluster_creation_result.stderr_lines }}"