diff --git a/hosts b/hosts index 8d7b683..5bc795c 100644 --- a/hosts +++ b/hosts @@ -1,8 +1,17 @@ [opensuse] -192.168.42.90 +192.168.42.4 +192.168.42.5 +192.168.42.6 +192.168.42.7 +192.168.42.8 +192.168.42.13 +192.168.42.15 + [debian] -192.168.42.42 +192.168.42.16 +192.168.42.17 +192.168.42.18 [centos] -192.168.42.69 \ No newline at end of file +192.168.42.21 diff --git a/roles/centos/tasks/main.yml b/roles/centos/tasks/main.yml new file mode 100644 index 0000000..e6d3983 --- /dev/null +++ b/roles/centos/tasks/main.yml @@ -0,0 +1,5 @@ +- name: Update packages using dnf + dnf: + name: "*" + state: latest + autoremove: yes diff --git a/roles/common/handlers/main.yml b/roles/common/handlers/main.yml deleted file mode 100644 index d70f481..0000000 --- a/roles/common/handlers/main.yml +++ /dev/null @@ -1,12 +0,0 @@ -- name: docker status - service: - name: docker - state: started - enabled: true - -- name: restart kubelet - service: - name: kubelet - daemon_reload: yes - state: restarted - enabled: true diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml deleted file mode 100644 index ed943ee..0000000 --- a/roles/common/tasks/main.yml +++ /dev/null @@ -1,77 +0,0 @@ -- 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: "{{ ansible_user_id }}" - 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 - notify: - - restart kubelet diff --git a/roles/debian/tasks/main.yml b/roles/debian/tasks/main.yml new file mode 100644 index 0000000..0831c0c --- /dev/null +++ b/roles/debian/tasks/main.yml @@ -0,0 +1,8 @@ +- name: Update repository cache using apt + apt: + update_cache: yes + +- name: Update packages using apt + apt: + upgrade: dist + autoremove: yes diff --git a/roles/master/tasks/main.yml b/roles/master/tasks/main.yml deleted file mode 100644 index c4ef3f2..0000000 --- a/roles/master/tasks/main.yml +++ /dev/null @@ -1,32 +0,0 @@ -- name: Initialize the Kubernetes cluster using kubeadm - command: kubeadm init --apiserver-advertise-address="{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}" - -- name: Creates .kube directory - file: - path: /home/{{ ansible_user_id }}/.kube - state: directory - -- 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: kubernetes_join_command_result - -- name: Set the kubeadm join command globally. - set_fact: - kubernetes_join_command: > - {{ kubernetes_join_command_result.stdout }} - when: kubernetes_join_command_result.stdout is defined - delegate_to: "{{ item }}" - delegate_facts: true - with_items: "{{ groups['all'] }}" diff --git a/roles/opensuse/tasks/main.yml b/roles/opensuse/tasks/main.yml new file mode 100644 index 0000000..c0cfccc --- /dev/null +++ b/roles/opensuse/tasks/main.yml @@ -0,0 +1,5 @@ +- name: Update packages using zypper + zypper: + name: '*' + state: latest + update_cache: yes diff --git a/roles/worker/tasks/main.yml b/roles/worker/tasks/main.yml deleted file mode 100644 index d6b9467..0000000 --- a/roles/worker/tasks/main.yml +++ /dev/null @@ -1,4 +0,0 @@ -- name: Join node to Kubernetes master - shell: > - {{ kubernetes_join_command }} - creates=/etc/kubernetes/kubelet.conf diff --git a/update.yml b/update.yml index 6438781..3ad8269 100644 --- a/update.yml +++ b/update.yml @@ -1,21 +1,21 @@ --- -- name: Apply common configuration to all nodes - hosts: all +- name: Update openSUSE virtual machines + hosts: opensuse become: true roles: - - common + - opensuse -- name: Configure and deploy Kubernetes master - hosts: master +- name: Update Debian and Ubuntu virtual machines + hosts: debian become: true roles: - - master + - debian -- name: Join workers to Kubernetes cluster - hosts: worker +- name: Update CentOS virtual machines + hosts: centos become: true roles: - - worker + - centos \ No newline at end of file