fix master
This commit is contained in:
parent
fd3d65fb78
commit
264d837298
87
common.yml
Normal file
87
common.yml
Normal file
@ -0,0 +1,87 @@
|
||||
---
|
||||
- hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- debug: var=hostvars[inventory_hostname]['ansible_default_ipv4']['address']
|
||||
- debug: var=hostvars[inventory_hostname]['ansible_default_ipv6']['address']
|
||||
- name: Install packages that allow apt to be used over HTTPS
|
||||
apt:
|
||||
name: "{{ packages }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
vars:
|
||||
packages:
|
||||
- aptitude
|
||||
- apt-transport-https
|
||||
- ca-certificates
|
||||
- curl
|
||||
- gnupg-agent
|
||||
- software-properties-common
|
||||
|
||||
- name: Add an apt signing key for Docker
|
||||
apt_key:
|
||||
url: https://download.docker.com/linux/ubuntu/gpg
|
||||
state: present
|
||||
|
||||
- name: Add apt repository for stable version
|
||||
apt_repository:
|
||||
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
|
||||
state: present
|
||||
|
||||
- name: Install docker and its dependecies
|
||||
apt:
|
||||
name: "{{ packages }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
vars:
|
||||
packages:
|
||||
- docker-ce
|
||||
- docker-ce-cli
|
||||
- containerd.io
|
||||
notify:
|
||||
- docker status
|
||||
|
||||
- name: Add user to docker group
|
||||
user:
|
||||
name: torma
|
||||
group: docker
|
||||
- name: Remove swapfile from /etc/fstab
|
||||
mount:
|
||||
name: "{{ item }}"
|
||||
fstype: swap
|
||||
state: absent
|
||||
with_items:
|
||||
- swap
|
||||
- none
|
||||
|
||||
- name: Disable swap
|
||||
command: swapoff -a
|
||||
when: ansible_swaptotal_mb > 0
|
||||
|
||||
- name: Add an apt signing key for Kubernetes
|
||||
apt_key:
|
||||
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
|
||||
state: present
|
||||
|
||||
- name: Adding apt repository for Kubernetes
|
||||
apt_repository:
|
||||
repo: deb https://apt.kubernetes.io/ kubernetes-xenial main
|
||||
state: present
|
||||
filename: kubernetes.list
|
||||
|
||||
- name: Install Kubernetes binaries
|
||||
apt:
|
||||
name: "{{ packages }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
vars:
|
||||
packages:
|
||||
- kubelet
|
||||
- kubeadm
|
||||
- kubectl
|
||||
|
||||
- name: Restart kubelet
|
||||
service:
|
||||
name: kubelet
|
||||
daemon_reload: yes
|
||||
state: restarted
|
@ -2,6 +2,8 @@
|
||||
- hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- debug: var=hostvars[inventory_hostname]['ansible_default_ipv4']['address']
|
||||
- debug: var=hostvars[inventory_hostname]['ansible_default_ipv6']['address']
|
||||
- name: Install packages that allow apt to be used over HTTPS
|
||||
apt:
|
||||
name: "{{ packages }}"
|
||||
@ -9,6 +11,7 @@
|
||||
update_cache: yes
|
||||
vars:
|
||||
packages:
|
||||
- aptitude
|
||||
- apt-transport-https
|
||||
- ca-certificates
|
||||
- curl
|
||||
@ -77,11 +80,6 @@
|
||||
- kubeadm
|
||||
- kubectl
|
||||
|
||||
- name: Configure node ip
|
||||
lineinfile:
|
||||
path: /etc/default/kubelet
|
||||
line: KUBELET_EXTRA_ARGS=--node-ip={{ node_ip }}
|
||||
|
||||
- name: Restart kubelet
|
||||
service:
|
||||
name: kubelet
|
||||
@ -89,25 +87,33 @@
|
||||
state: restarted
|
||||
|
||||
- name: Initialize the Kubernetes cluster using kubeadm
|
||||
command: kubeadm init --apiserver-advertise-address="192.168.50.10" --apiserver-cert-extra-sans="192.168.50.10" --node-name k8s-master --pod-network-cidr=192.168.0.0/16
|
||||
command: kubeadm init --apiserver-advertise-address="{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
|
||||
|
||||
- name: Setup kubeconfig for vagrant user
|
||||
command: "{{ item }}"
|
||||
with_items:
|
||||
- mkdir -p /home/vagrant/.kube
|
||||
- cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config
|
||||
- chown vagrant:vagrant /home/vagrant/.kube/config
|
||||
- name: Creates .kube directory
|
||||
file:
|
||||
path: /home/{{ ansible_user_id }}/.kube
|
||||
state: directory
|
||||
|
||||
- name: Install calico pod network
|
||||
become: false
|
||||
command: kubectl create -f https://docs.projectcalico.org/v3.4/getting-started/kubernetes/installation/hosted/calico.yaml
|
||||
- name: Copy files needed for kubectl
|
||||
copy:
|
||||
remote_src: yes
|
||||
src: /etc/kubernetes/admin.conf
|
||||
dest: /home/{{ ansible_user_id }}/.kube/config
|
||||
owner: "{{ ansible_user_id }}"
|
||||
group: users
|
||||
|
||||
- name: set up weave network
|
||||
shell: export KUBECONFIG=/etc/kubernetes/admin.conf && export kubever=$(kubectl version | base64 | tr -d '\n') && kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever"
|
||||
register: weavenet_out
|
||||
|
||||
- name: Generate join command
|
||||
command: kubeadm token create --print-join-command
|
||||
register: join_command
|
||||
shell: kubeadm token create --print-join-command > /tmp/join_command
|
||||
|
||||
- name: Copy join command to local file
|
||||
local_action: copy content="{{ join_command.stdout_lines[0] }}" dest="./join-command"
|
||||
- name: Specifying a destination path
|
||||
fetch:
|
||||
src: /tmp/join_command
|
||||
dest: /tmp/ansible/join_command
|
||||
flat: yes
|
||||
|
||||
handlers:
|
||||
- name: docker status
|
||||
|
Loading…
Reference in New Issue
Block a user