Skip to content

Commit

Permalink
Merge pull request #24 from ricsanfre/fix/ansiblelint
Browse files Browse the repository at this point in the history
Ansible playbooks refactoring for solving ansible-lint issues
  • Loading branch information
ricsanfre authored Dec 13, 2021
2 parents ddb6b97 + 7a8cd46 commit c8ea299
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 25 deletions.
1 change: 1 addition & 0 deletions ansible/roles/basic_setup/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@
path: /boot/firmware/config.txt
line: "gpu_mem=16"
create: true
mode: 0755
notify: reboot
12 changes: 10 additions & 2 deletions ansible/roles/k3s/master/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
---

- name: Get K3s installation script
get_url:
url: https://get.k3s.io
dest: /tmp/k3s_install.sh
mode: '0766'

- name: Install K3s
shell:
cmd: "curl -sfL https://get.k3s.io | K3S_TOKEN={{ k3s_token }} sh -s - server {{ k3s_server_extra_args }}"
command: "/tmp/k3s_install.sh server {{ k3s_server_extra_args }}"
environment:
K3S_TOKEN: "{{ k3s_token }}"
changed_when: true

- name: Create directory .kube
file:
Expand Down
13 changes: 11 additions & 2 deletions ansible/roles/k3s/worker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
---

- name: Get K3s installation script
get_url:
url: https://get.k3s.io
dest: /tmp/k3s_install.sh
mode: '0766'

- name: Install K3s
shell:
cmd: "curl -sfL https://get.k3s.io | K3S_URL='https://{{ k3s_master_ip }}:6443' K3S_TOKEN={{ k3s_token }} sh -s - {{ k3s_worker_extra_args }}"
command: "/tmp/k3s_install.sh {{ k3s_worker_extra_args }}"
environment:
K3S_TOKEN: "{{ k3s_token }}"
K3S_URL: "https://{{ k3s_master_ip }}:6443"
changed_when: true
15 changes: 10 additions & 5 deletions ansible/roles/longhorn/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@
with_items:
- longhorn_ingress.yml.j2

- name: Remove Local-Path as default storage class
command:
cmd: >
kubectl patch storageclass local-path -p
'{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
- name: Patching Local-path storage resource. Set it as non-default
kubernetes.core.k8s:
definition:
apiVersion: v1
kind: StorageClass
metadata:
name: local-path
annotations:
storageclass.kubernetes.io/is-default-class: "false"
state: present
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
cmd: >-
htpasswd -nb {{ traefik_basic_auth_user }} {{ traefik_basic_auth_passwd }} | base64
register: htpasswd
changed_when: false

- name: Set htpasswd pair
set_fact:
Expand Down
52 changes: 36 additions & 16 deletions ansible/tasks/cleaning.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
---
- name: Clean Longhorn storage
shell: "rm -rf /storage/*"
args:
executable: /bin/bash
changed_when: true

- name: Clean Longhorn storage | get content
become: true
find:
paths: /storage
patterns: '*'
file_type: any
hidden: true
register: directory_content_result

- name: Clean Longhorn storage | delete content
become: true
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ directory_content_result.files }}"

- name: Clean longhorn iscsi targets and nodes
shell: |
set -o pipefail
for i in `sudo iscsiadm -m discovery -o show | grep -v 10.0.0.1 | awk '{print $1}'`
do
echo "Deleting target $i"
sudo iscsiadm -m discovery -p $i -o delete
done
args:
executable: /bin/bash
register: output
changed_when: true

- name: Clean container/pod logs
shell: "rm -rf /var/log/pods /var/log/containers"
args:
executable: /bin/bash
ignore_errors: true
changed_when: true
file:
path: "{{ item }}"
state: absent
with_items:
- "/var/log/pods"
- "/var/log/containers"

- name: Clean fluentd pos files
shell: "rm /var/log/*.pos"
args:
executable: /bin/bash
ignore_errors: true
changed_when: true
- name: Clean fluentd pos files | get pos files
find:
paths: /var/log
patterns: '*.pos'
register: files_to_delete

- name: Clean fluentd pos files | delete pos files
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ files_to_delete.files }}"

0 comments on commit c8ea299

Please sign in to comment.