Skip to content

Commit

Permalink
update all
Browse files Browse the repository at this point in the history
  • Loading branch information
xfgjdsytdsg committed Sep 24, 2021
1 parent 10ae863 commit 5b71269
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
87 changes: 87 additions & 0 deletions .taskfiles/ansible.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
version: "3"

env:
ANSIBLE_CONFIG: "{{.PROJECT_DIR}}/ansible/ansible.cfg"

vars:
ANSIBLE_PLAYBOOK_DIR: "{{.ANSIBLE_DIR}}/playbooks"
ANSIBLE_INVENTORY_DIR: "{{.ANSIBLE_DIR}}/inventory"

tasks:
deps:
desc: Upgrade Ansible galaxy deps
dir: ansible
cmds:
- "ansible-galaxy install -r requirements.yml --force"
- "pip3 install -r requirements.txt"
silent: true

list:
desc: List all the hosts
dir: ansible
cmds:
- "ansible all -i {{.ANSIBLE_INVENTORY_DIR}}/home-cluster/hosts.yml --list-hosts"
silent: true

ping:
desc: Ping all the hosts
dir: ansible
cmds:
- "ansible all -i {{.ANSIBLE_INVENTORY_DIR}}/home-cluster/hosts.yml --one-line -m 'ping'"
silent: true

uptime:
desc: Uptime of all the hosts
dir: ansible
cmds:
- ansible all -i {{.ANSIBLE_INVENTORY_DIR}}/home-cluster/hosts.yml --one-line -a 'uptime'
silent: true

clean-images:
desc: Clean up stale container images
dir: ansible
cmds:
- "ansible kubernetes -i {{.ANSIBLE_INVENTORY_DIR}}/home-cluster/hosts.yml --one-line -a 'k3s crictl rmi --prune' --become"
silent: true

purge-manifests:
desc: Delete all manifests under /var/lib/rancher/k3s/server/manifests
dir: ansible
cmds:
- "ansible master -i {{.ANSIBLE_INVENTORY_DIR}}/home-cluster/hosts.yml --one-line -a 'rm /var/lib/rancher/k3s/server/manifests/*' --become"

reboot:
desc: Reboot all the k8s nodes
dir: ansible
cmds:
- "ansible kubernetes -i {{.ANSIBLE_INVENTORY_DIR}}/home-cluster/hosts.yml -a '/usr/bin/systemctl reboot' --become"
silent: true

poweroff:
desc: Shutdown all the k8s nodes
dir: ansible
cmds:
- "ansible kubernetes -i {{.ANSIBLE_INVENTORY_DIR}}/home-cluster/hosts.yml -a '/usr/bin/systemctl poweroff' --become"
silent: true

playbook:debian-prepare:
desc: Prepare all the k8s nodes for running k3s
dir: ansible
cmds:
- "ansible-playbook -i {{.ANSIBLE_INVENTORY_DIR}}/home-cluster/hosts.yml {{.ANSIBLE_PLAYBOOK_DIR}}/kubernetes/debian-prepare.yml"
silent: true

playbook:debian-upgrade:
desc: Upgrade all the k8s nodes operating system
dir: ansible
cmds:
- "ansible-playbook -i {{.ANSIBLE_INVENTORY_DIR}}/home-cluster/hosts.yml {{.ANSIBLE_PLAYBOOK_DIR}}/kubernetes/debian-upgrade.yml"
silent: true

playbook:cluster-install:
desc: Install Kubernetes on the nodes
dir: ansible
cmds:
- "ansible-playbook -i {{.ANSIBLE_INVENTORY_DIR}}/home-cluster/hosts.yml {{.ANSIBLE_PLAYBOOK_DIR}}/kubernetes/k3s-install.yml"
silent: true
2 changes: 2 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ vars:
PROJECT_DIR:
sh: "git rev-parse --show-toplevel"
CLUSTER_DIR: "{{.PROJECT_DIR}}/cluster"
ANSIBLE_DIR: "{{.PROJECT_DIR}}/ansible"

env:
KUBECONFIG: "{{.PROJECT_DIR}}/kubeconfig"

includes:
ansible: .taskfiles/ansible.yml
flux: .taskfiles/flux.yml
format: .taskfiles/format.yml
lint: .taskfiles/lint.yml
Expand Down
17 changes: 17 additions & 0 deletions ansible/playbooks/kubernetes/debian-upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- hosts:
- storage
become: true
gather_facts: true
any_errors_fatal: true
tasks:
- name: upgrade
ansible.builtin.apt:
upgrade: full
update_cache: true
cache_valid_time: 3600
autoclean: true
autoremove: true
register: apt_upgrade
retries: 5
until: apt_upgrade is success

0 comments on commit 5b71269

Please sign in to comment.