initial checkin

This commit is contained in:
Radar231 2021-07-22 23:14:55 -04:00
commit 03ba61cf97
2 changed files with 79 additions and 0 deletions

20
README.md Normal file
View File

@ -0,0 +1,20 @@
# Ansible Role: k3s
## Introduction
This role will install a k3s cluster to three or more target hosts.
This role requires at least three target hosts, previously deployed. Each
host should have at least 4GB of RAM and at least a 20GB disk.
It is also assumed that the user running the playbook has SSH key access
set up for the root user on the target hosts.
This playbook can be run using the following command line;
ansible-playbook -i <inventory file> -e "username=<username>" k3s.yml
ie,
ansible-playbook -i cluster_inventory.yml -e "username=joe" k3s.yml

59
tasks/main.yml Normal file
View File

@ -0,0 +1,59 @@
---
# tasks file for main.yml
###########################################################
- name: Check to make sure we have at least {{ minhosts }} target hosts (if cluster)
fail:
msg: "You need to have at least {{ minhosts }} target hosts for a cluster!"
when: (do_cluster == true) and (minhosts > numhosts)
###########################################################
- name: Install k3s server on master
shell:
cmd: curl -sfL https://get.k3s.io | sh -
when: "'master' in group_names"
###########################################################
- name: create /home/{{ username }}/.kube
file:
path: "/home/{{ username }}/.kube"
state: directory
owner: "{{ username }}"
group: "{{ username }}"
mode: "0755"
when: (username != "root") and ('master' in group_names)
###########################################################
- name: Copy kubernetes admin conf to user .kube directory
copy:
remote_src: true
src: "/etc/rancher/k3s/k3s.yaml"
dest: "/home/{{ username }}/.kube/config"
owner: "{{ username }}"
group: "{{ username }}"
mode: "0600"
when: (username != "root") and ('master' in group_names)
###########################################################
- name: Add "KUBECONFIG" environment variables to .bashrc
blockinfile:
path: "/home/{{ username }}/.bashrc"
block: |
export KUBECONFIG=${HOME}/.kube/config
when: (username != "root") and ('master' in group_names)
###########################################################
- name: Retrieve nodetoken from master node
shell:
cmd: cat /var/lib/rancher/k3s/server/node-token
register: nodetoken
delegate_to: "{{ hostvars[groups['master'][0]].inventory_hostname }}"
when: do_cluster == true
###########################################################
- name: Run agent command on worker nodes
shell:
cmd: curl -sfL https://get.k3s.io | K3S_URL=https://{{ hostvars[groups['master'][0]].ansible_host }}:6443 K3S_TOKEN={{ nodetoken.stdout }} sh -
when: (do_cluster == true) and ('workers' in group_names)
# EOF