This commit is contained in:
2024-04-02 21:58:26 +02:00
parent 8a7c4f3724
commit 6a2fbcee07
9 changed files with 219 additions and 0 deletions

View File

@ -0,0 +1,11 @@
- hosts: "{{ hosts }}"
become: yes
tasks:
- name: install core packages
apt:
name:
- prometheus-node-exporter
- nfs-common
update_cache: yes

View File

@ -0,0 +1,29 @@
- hosts:
- srv-prod-1.home.clcreative.de
- srv-prod-2.home.clcreative.de
become: yes
tasks:
# Breaks existing Docker Servers!
# Change Tasks for separate group!
# Install Docker
# - name: install prerequisites
# apt:
# name:
# - docker.io
# update_cache: yes
# - name: add user permissions
# shell: "usermod -aG docker {{ ansible_env.SUDO_USER }}"
# - name: Reset ssh connection for changes to take effect
# meta: "reset_connection"
# Install Docker Compose
- name: install docker-compose
apt:
name:
- docker-compose
update_cache: yes

View File

@ -0,0 +1,23 @@
- hosts: all
become: yes
tasks:
# Deploy SSH Key
# --
- name: install public keys
ansible.posix.authorized_key:
user: "{{ lookup('env','USER') }}"
state: present
key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
# Set all sudoers to no password
# --
- name: change sudoers file
lineinfile:
path: /etc/sudoers
state: present
regexp: '^%sudo'
line: '%sudo ALL=(ALL) NOPASSWD: ALL'
validate: /usr/sbin/visudo -cf %s

View File

@ -0,0 +1,19 @@
- hosts: "{{ hosts }}"
become: yes
tasks:
- name: install core packages
apt:
name:
- prometheus-node-exporter
- nfs-common
- qemu-guest-agent
- unzip
update_cache: yes
- name: start guest qemu-guest-agent
service:
name: qemu-guest-agent
state: started
enabled: yes

View File

@ -0,0 +1,29 @@
- hosts: "{{ hosts }}"
become: yes
tasks:
# Upgrade packages
- name: upgrade apt packages
become: true
apt:
upgrade: yes
update_cache: yes
# Check if reboot is required
- name: check if system reboot is required
become: true
stat:
path: /var/run/reboot-required
register: reboot_required
# Send Discord message when reboot is required
- name: Send Discord message
uri:
url: "{{ discord_webhook_url }}"
method: POST
body_format: json
body: '{"content": "Reboot required on {{ inventory_hostname }}"}'
headers:
Content-Type: application/json
status_code: 204
when: reboot_required.stat.exists

View File

@ -0,0 +1,23 @@
- hosts: "{{ hosts }}"
tasks:
- name: Get disk usage
command: df -h
register: disk_usage
- name: Check disk space available
shell: df -h / | awk 'NR==2 {print $5}'
register: disk_usage
# Send Discord message when disk space is over 80%
- name: Send Discord message
uri:
url: "{{ discord_webhook_url }}"
method: POST
body_format: json
body: '{"content": "Disk space on {{ inventory_hostname }} is above 80%!"}'
headers:
Content-Type: application/json
status_code: 204
when: disk_usage.stdout[:-1]|int > 80

View File

@ -0,0 +1,13 @@
- hosts: "{{ hosts }}"
tasks:
- name: Prune non-dangling, and dangling images
community.docker.docker_prune:
containers: false
images: true
images_filters:
dangling: false
networks: false
volumes: false
builder_cache: false