kue/ansible/site.yaml
Mohammed Naser 59a21bccb0 add sonobuoy
Change-Id: Ie526331006c3761afb41425de784609d37156573
2019-08-21 19:08:56 -04:00

164 lines
4.2 KiB
YAML

---
# Copyright 2019 VEXXHOST, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Bootstrap nodes
hosts: all
strategy: free
tasks:
- name: Disable swap
become: true
shell: swapoff -a
- name: Enable forwarding
become: true
shell: iptables -P FORWARD ACCEPT
- name: Add repository keys
become: true
apt_key:
url: "{{ item }}"
state: present
loop:
- https://download.docker.com/linux/ubuntu/gpg
- https://packages.cloud.google.com/apt/doc/apt-key.gpg
- name: Add repository
become: true
apt_repository:
repo: "{{ item }}"
state: present
loop:
- "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
- "deb https://apt.kubernetes.io/ kubernetes-xenial main"
- name: Install packages
become: true
apt:
name:
- docker-ce=18.06.2~ce~3-0~ubuntu
- kubelet=1.15.2-00
- kubeadm=1.15.2-00
- kubectl=1.15.2-00
- name: Enable services
become: true
service:
name: "{{ item }}"
state: started
enabled: true
loop:
- docker
- kubelet
- name: Setup resolvers
become: true
copy:
dest: /etc/kubernetes/resolv.conf
content: |
nameserver 1.1.1.1
- name: Drop configuration file
become: true
copy:
dest: /etc/kubernetes/kubeadm.conf
content: |
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
resolv-conf: /etc/kubernetes/resolv.conf
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
networking:
podSubnet: 10.244.0.0/16
- name: Bootstrap cluster
hosts: masters[0]
gather_facts: false
tasks:
- name: Wait for bootstrap node to go up
wait_for_connection:
timeout: 300
- name: Initialize cluster
become: true
shell: |
kubeadm init --config /etc/kubernetes/kubeadm.conf
args:
creates: /etc/kubernetes/manifests/kube-apiserver.yaml
- name: Join nodes to cluster
hosts: all:!masters[0]
strategy: free
gather_facts: false
tasks:
- name: Wait for nodes to go up
wait_for_connection:
timeout: 300
- name: Check if we're already part of the cluster
become: true
register: apiserver_stat
stat:
path: /etc/kubernetes/kubelet.conf
- name: Generate token for cluster join
become: true
delegate_to: "{{ groups['masters'][0] }}"
register: kubeadm_token_create
shell: |
kubeadm token create --ttl 5m --print-join-command
when:
- not apiserver_stat.stat.exists
- name: Join cluster
become: true
shell: "{{ kubeadm_token_create.stdout }}"
when:
- not apiserver_stat.stat.exists
- name: Configure administration access
hosts: masters
gather_facts: false
tasks:
- name: Create configuration folders
file:
path: "/home/{{ ansible_user }}/{{ item }}"
state: directory
loop:
- .kube
- manifests
- name: Copy configuration file
become: true
copy:
src: /etc/kubernetes/admin.conf
dest: "/home/{{ ansible_user }}/.kube/config"
remote_src: true
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
- name: Install manifests
hosts: masters
gather_facts: false
tasks:
- name: Apply flannel configuration
run_once: true
changed_when: false
shell: |
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml