Skip to content

Instantly share code, notes, and snippets.

@apatil
Created November 4, 2016 18:41
Show Gist options
  • Save apatil/30e705e7de22ffeacd9a95316d490010 to your computer and use it in GitHub Desktop.
Save apatil/30e705e7de22ffeacd9a95316d490010 to your computer and use it in GitHub Desktop.
---
- hosts: master,nodes
become: True
become_user: root
become_method: sudo
vars_files:
- config.yml
vars:
k8s_version: 1.3.7
docker_version: 1.11.2
tasks:
- name: detect os (RHEL/Ubuntu)
set_fact: rhel={{ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'}}
- name: upgrade all base packages
yum: name=* state=latest update_cache=yes
when: upgrade_system
- name: install useful debugging packages
yum: name={{item}} state=present update_cache=yes
with_items:
- git
- ntp
- curl
- wget
- tmux
- emacs
- vim
- nfs-utils
- ca-certificates
- bridge-utils
- lvm2
- btrfs-progs
- sysstat
- iotop
- htop
- tcpdump
- nc
- iftop
- dstat
- postgresql
- name: stop all services if they are running
service: name={{item}} state=stopped enabled=yes
with_items:
- flannel
- docker
- kubelet
- kube-proxy
ignore_errors: yes
- name: stop all master only services if they are running
service: name={{item}} state=stopped enabled=yes
with_items:
- etcd
- nfs
- kube-apiserver
- kube-scheduler
- kube-controller-manager
when: '"master" in group_names'
ignore_errors: yes
- name: disable firewalld if enabled
service: name=firewalld state=stopped enabled=no
ignore_errors: yes
- name: enabled ntpd
service: name=ntpd state=started enabled=yes
- name: install etcd
shell: |
wget https://github.com/coreos/etcd/releases/download/v2.3.7/etcd-v2.3.7-linux-amd64.tar.gz && \
tar -zxvf etcd-v2.3.7-linux-amd64.tar.gz && \
cp etcd-v2.3.7-linux-amd64/etc* /usr/bin
rm -rf etcd-v2.3.7-linux-amd64
rm etcd-v2.3.7-linux-amd64.tar.gz
args:
warn: no
creates: /usr/bin/etcd
- name: install etcd unit
template:
src: systemd/etcd.service
dest: /etc/systemd/system/etcd.service
when: '"master" in group_names'
notify:
- reload systemd
- reload etcd
- name: install flannel
shell: |
wget https://github.com/coreos/flannel/releases/download/v0.6.1/flannel-v0.6.1-linux-amd64.tar.gz && \
tar -zxvf flannel-v0.6.1-linux-amd64.tar.gz && \
mv flanneld /usr/bin && \
mv mk-docker-opts.sh /usr/bin
rm flannel-v0.6.1-linux-amd64.tar.gz
args:
warn: no
creates: /usr/bin/flanneld
- name: install flannel unit
template:
src: systemd/flannel.service
dest: /etc/systemd/system/flannel.service
notify:
- reload systemd
- reload flannel
- name: add docker repository
copy:
src: etc/yum.repos.d/docker.repo
dest: /etc/yum.repos.d/docker.repo
mode: 700
- name: install docker-engine
yum: name=docker-engine-{{docker_version}}-1.el7.centos state=latest update_cache=yes
- name: update docker wait service
template:
src: systemd/docker-wait.service
dest: /etc/systemd/system/docker-wait.service
notify:
- reload systemd
- reload docker
- name: update docker service
template:
src: systemd/docker.service
dest: /etc/systemd/system/docker.service
notify:
- reload systemd
- reload docker
- name: download and upgrade hyperkube, kubectl
get_url: url=https://storage.googleapis.com/kubernetes-release/release/v{{k8s_version}}/bin/linux/amd64/{{item}} dest=/usr/bin/{{item}}
with_items:
- hyperkube
- kubectl
- name: set permissions for hyperkube, kubectl
file:
path: /usr/bin/{{item}}
owner: root
group: root
mode: 0755
with_items:
- hyperkube
- kubectl
- name: create the kubernetes configuration directory
file:
path: /etc/kubernetes
state: directory
owner: root
group: root
mode: 0775
- name: install kubelet service
template:
src: systemd/kubelet.service
dest: /etc/systemd/system/kubelet.service
notify:
- reload systemd
- reload kubelet
- name: install kube-proxy service
template:
src: systemd/kube-proxy.service
dest: /etc/systemd/system/kube-proxy.service
notify:
- reload systemd
- reload kube-proxy
- name: install kube-apiserver service
template:
src: systemd/kube-apiserver.service
dest: /etc/systemd/system/kube-apiserver.service
when: '"master" in group_names'
notify:
- reload systemd
- reload kube-apiserver
- name: install kube-controller-manager service
template:
src: systemd/kube-controller-manager.service
dest: /etc/systemd/system/kube-controller-manager.service
when: '"master" in group_names'
notify:
- reload systemd
- reload kube-controller-manager
- name: install kube-scheduler service
template:
src: systemd/kube-scheduler.service
dest: /etc/systemd/system/kube-scheduler.service
when: '"master" in group_names'
notify:
- reload systemd
- reload kube-scheduler
- name: reload systemd
command: systemctl daemon-reload
- name: start all master only services
service: name={{item}} state=started enabled=yes
with_items:
- etcd
- kube-apiserver
- kube-scheduler
- kube-controller-manager
when: '"master" in group_names'
- name: start all services
service: name={{item}} state=started enabled=yes
with_items:
- flannel
- kubelet
- kube-proxy
- name: start docker, retrying on failure.
service: name=docker state=started enabled=yes
register: result
until: result|success
retries: 10
delay: 10
- name: add /etc/exports
template:
src: etc/exports
dest: /etc/exports
when: '"master" in group_names'
notify: reload nfs
- name: start and enable nfs
service: name={{item}} state=started enabled=yes
with_items:
- rpcbind
- nfs-server
- nfs-lock
- nfs-idmap
when: '"master" in group_names'
handlers:
- name: reload systemd
command: systemctl daemon-reload
- name: reload etcd
service: name=etcd state=started enabled=yes
- name: reload docker
service: name=docker state=started enabled=yes
- name: reload flannel
service: name=flannel state=started enabled=yes
- name: reload kubelet
service: name=kubelet state=restarted enabled=yes
- name: reload kube-proxy
service: name=kube-proxy state=restarted enabled=yes
- name: reload kube-apiserver
service: name=kube-apiserver state=restarted enabled=yes
- name: reload kube-controller-manager
service: name=kube-controller-manager state=restarted enabled=yes
- name: reload kube-scheduler
service: name=kube-scheduler state=restarted enabled=yes
- name: reload nfs
service: name={{item}} state=restarted enabled=yes
with_items:
- rpcbind
- nfs-server
- nfs-lock
- nfs-idmap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment