Compare commits

..

6 commits

Author SHA1 Message Date
bb5ee5085f add new zabbix template so we can automatically add new checks 2025-07-14 18:35:42 +02:00
242a6d1cca new firewall system
Render the template system wide, then apply.  This way, the
appdefinition.yml can contain everything that is required, and we don't
have to specify this anymore in the main config
2025-07-14 18:35:05 +02:00
cd8e0cbad7 setup the app using ppm setup 2025-07-14 18:33:32 +02:00
1df77aa74d install zabbix agent in the baseline 2025-07-14 18:32:39 +02:00
c7a3cb40e9 remove deprecated ansible config 2025-07-14 18:31:01 +02:00
d9c8951e60 remove ansible_managed
This has been deprecated by ansible
2025-07-14 18:30:42 +02:00
20 changed files with 166 additions and 39 deletions

View file

@ -2,9 +2,8 @@
inventory=inventory inventory=inventory
retry_files_enabled = False retry_files_enabled = False
remote_user = root remote_user = root
ansible_managed = DO NOT MODIFY: this file is managed by ansible!
deperaction_warnings = True deperaction_warnings = True
display_skipped_hosts = True display_skipped_hosts = True
stdout_callback = yaml result_format=yaml
stderr_callback = yaml

View file

@ -15,11 +15,6 @@ ppm_apps:
- on_server: ppm.pfoe.be - on_server: ppm.pfoe.be
user: nginx user: nginx
chicken_egg_appdefinition: ../nginx/ chicken_egg_appdefinition: ../nginx/
firewall_redirect:
- from: 8080
to: 80
- from: 8443
to: 443
appconfig: appconfig:
appinfo: appinfo:
url: https://ppm.pfoe.be/ppm/nginx.git url: https://ppm.pfoe.be/ppm/nginx.git

View file

@ -0,0 +1,2 @@
zabbix_server: "{{ lookup('file', 'passwords/zabbix_server') }}"
zabbix_psk: "{{ lookup('file', 'passwords/zabbix_psk') }}"

View file

@ -0,0 +1 @@
zabbix ALL=(ALL) NOPASSWD: /usr/sbin/smartctl

View file

@ -6,3 +6,8 @@
ansible.builtin.systemd: ansible.builtin.systemd:
name: ssh name: ssh
state: restarted state: restarted
- name: Restart zabbix-agent2
ansible.builtin.service:
name: zabbix-agent2
state: restarted

View file

@ -7,5 +7,8 @@
- name: Manage root user - name: Manage root user
ansible.builtin.import_tasks: rootuser.yml ansible.builtin.import_tasks: rootuser.yml
- name: Get zabbix agent installed
ansible.builtin.import_tasks: zabbix.yml
- name: Ensure handlers have ran - name: Ensure handlers have ran
ansible.builtin.meta: flush_handlers ansible.builtin.meta: flush_handlers

View file

@ -0,0 +1,41 @@
- name: Install zabbix related packages
ansible.builtin.apt:
pkg:
- zabbix-agent2
# To monitor our physical disks health, not needed for vm's.
- smartmontools
- name: Zabbix firewall
ansible.builtin.template:
dest: /etc/firewall.d/zabbix
group: root
owner: root
mode: "0755"
src: zabbix-firewall.j2
notify: Restart firewall
- name: Write psk file
ansible.builtin.copy:
content: "{{ zabbix_psk }}\n"
dest: /etc/zabbix/zabbix.psk
group: root
owner: root
mode: "0644"
notify: Restart zabbix-agent2
- name: Zabbix agent config file
ansible.builtin.template:
dest: /etc/zabbix/zabbix_agent2.d/ansible.conf
group: root
owner: root
mode: "0644"
src: zabbix-agent.j2
notify: Restart zabbix-agent2
- name: Zabbix sudoers file
ansible.builtin.copy:
dest: /etc/sudoers.d/zabbix
group: root
owner: root
mode: "0644"
src: zabbix-sudoers

View file

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# {{ ansible_managed }} # This file is managed by ansible, do not modify!
# IPv4: # IPv4:
iptables -F iptables -F
@ -75,4 +75,4 @@ ip6tables -A INPUT -j REJECT
iptables -A FORWARD -j REJECT iptables -A FORWARD -j REJECT
ip6tables -A FORWARD -j REJECT ip6tables -A FORWARD -j REJECT
# {{ansible_managed}} # This file is managed by ansible, do not modify!

View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# {{ansible_managed}} # DO NOT MODIFY: this file is written by ansible
# Firewall to allow mosh sessions # Firewall to allow mosh sessions
ip6tables -A INPUT -p udp --match multiport --dports 60001:60020 -j ACCEPT ip6tables -A INPUT -p udp --match multiport --dports 60001:60020 -j ACCEPT

View file

@ -0,0 +1,10 @@
Server={{ zabbix_server }}
ServerActive=
TLSConnect=psk
TLSAccept=psk
TLSPSKFile=/etc/zabbix/zabbix.psk
TLSPSKIdentity={{ inventory_hostname }}
UserParameter=smartctl.health[*],sudo /usr/sbin/smartctl -H /dev/$1 | grep 'overall-health' | awk '{print $NF}'

View file

@ -0,0 +1,5 @@
#!/bin/bash
# Zabbix agent firewall
iptables -A INPUT -p tcp -s {{ zabbix_server }} --dport 10050 -j ACCEPT

View file

@ -0,0 +1,22 @@
#!/bin/bash
# PPM Firewall
{% for app in otherapps -%}
{%- if "firewall" in otherapps[app]["imports"] -%}
{%- set oneapp = otherapps[app]["imports"]["firewall"] %}
{% for redirect in oneapp.redirect %}
# Redirect {{ redirect.from }} to {{ redirect.to }} ({{ redirect.proto | default('tcp') }}) for {{ app }}
iptables -A INPUT -p {{ redirect.proto | default('tcp') }} --dport {{ redirect.to }} -j ACCEPT
ip6tables -A INPUT -p {{ redirect.proto | default('tcp') }} --dport {{ redirect.to }} -j ACCEPT
iptables -t nat -A PREROUTING -p {{ redirect.proto | default('tcp') }} --dport {{ redirect.from }} -j REDIRECT --to-ports {{ redirect.to }}
ip6tables -t nat -A PREROUTING -p {{ redirect.proto | default('tcp') }} --dport {{ redirect.from }} -j REDIRECT --to-ports {{ redirect.to }}
{% endfor %}
{% for openport in oneapp.open %}
# Open port {{ openport.port }}/{{ openport.proto | default('tcp') }} for app {{ app }}
iptables -A INPUT -p {{ openport.proto | default('tcp') }} --dport {{ openport.port }} -j ACCEPT
ip6tables -A INPUT -p {{ openport.proto | default('tcp') }} --dport {{ openport.port }} -j ACCEPT
{% endfor %}
{% endif %}
{% endfor %}

View file

@ -0,0 +1,12 @@
# Zabbix agent config for ppm
{%- set ns = namespace() -%}
{%- set ns.allchecks = [] -%}
{%- for app in otherapps -%}
{%- if "monitoring" in otherapps[app]["imports"] -%}
{%- for check in otherapps[app]["imports"]["monitoring"]["checks"] %}
{%- set ns.allchecks = ns.allchecks + [check | combine({'app':app})] -%}
{% endfor -%}{%- endif -%}{%- endfor %}
UserParameter=ppm.discover,/bin/echo '{{ ns.allchecks | tojson }}'
UserParameter=ppm.app[*],/bin/bash -c 'echo $2 | nc -U {{ statedir }}/$1.monitoring'

View file

@ -1,3 +1,8 @@
- name: Restart firewall - name: Restart firewall
ansible.builtin.command: /etc/network/if-pre-up.d/firewall ansible.builtin.command: /etc/network/if-pre-up.d/firewall
changed_when: true changed_when: true
- name: Restart zabbix-agent2
ansible.builtin.service:
name: zabbix-agent2
state: restarted

View file

@ -0,0 +1,13 @@
- name: Configure firewall options
ansible.builtin.copy:
dest: /home/.ppmfirewalltemplate
group: root
owner: root
mode: "0755"
src: ppmfirewall
- name: Render firewall
ansible.builtin.shell: ppm template /home/.ppmfirewalltemplate /etc/firewall.d/ppmfirewall ; chmod 755 /etc/firewall.d/ppmfirewall
register: firewall_render
changed_when: "'content did not change' not in firewall_render.stdout"
notify: Restart firewall

View file

@ -9,11 +9,8 @@
label: "{{ ppm_app.user }}" label: "{{ ppm_app.user }}"
when: ppm_app.on_server == inventory_hostname when: ppm_app.on_server == inventory_hostname
- name: Configure firewall options - name: Arrange firewall
ansible.builtin.template: ansible.builtin.import_tasks: firewall.yml
dest: /etc/firewall.d/ppmfirewall
group: root - name: Arrange zabbix
owner: root ansible.builtin.import_tasks: zabbix.yml
mode: "0755"
src: ppmfirewall.j2
notify: Restart firewall

View file

@ -34,3 +34,25 @@
- name: "Bootstrap the app definition ({{ ppm_app.user }})" - name: "Bootstrap the app definition ({{ ppm_app.user }})"
ansible.builtin.include_tasks: copyappdef.yml ansible.builtin.include_tasks: copyappdef.yml
when: ppm_app.chicken_egg_appdefinition is defined and not appdefinition.stat.exists when: ppm_app.chicken_egg_appdefinition is defined and not appdefinition.stat.exists
- name: "Set up extra files for {{ ppm_app.user }}"
ansible.builtin.copy:
src: "{{ item.from }}"
dest: "{{ ppm_app_user.home }}/{{ item.to }}"
mode: "{{ item.mode | default('0644') }}"
owner: "{{ ppm_app_user.name }}"
group: "{{ ppm_app_user.group }}"
loop: "{{ ppm_app.extra_files | default([]) }}"
- name: "Setup and run app ({{ ppm_app.user }})"
ansible.builtin.command: ppm setup --start
register: ppm_setupstart
changed_when: "'No changes have been made, everything was already ok' not in ppm_setupstart.stdout"
become: true
become_user: "{{ ppm_app.user }}"
environment:
XDG_RUNTIME_DIR: "/run/user/{{ ppm_app_user.uid }}"
- name: Show ppm output
ansible.builtin.debug:
var: ppm_setupstart

View file

@ -19,6 +19,8 @@
- python3-jsonschema - python3-jsonschema
# Git is required for checking out the app definitions # Git is required for checking out the app definitions
- git - git
# Yeah we should use nftables, patches welcome. For now, we install iptables
- iptables
- name: Create state directory - name: Create state directory
ansible.builtin.file: ansible.builtin.file:

View file

@ -0,0 +1,13 @@
- name: Configure firewall options
ansible.builtin.copy:
dest: /home/.zabbixagenttemplate
group: root
owner: root
mode: "0755"
src: ppmzabbixagent
- name: Render zabbix template
ansible.builtin.command: ppm template /home/.zabbixagenttemplate /etc/zabbix/zabbix_agent2.d/ppm.conf
register: zabbix_render
changed_when: "'content did not change' not in zabbix_render.stdout"
notify: Restart zabbix-agent2

View file

@ -1,20 +0,0 @@
#!/bin/bash
# PPM Firewal, written by ansible
{% for ppm_app in ppm_apps %}
# Firewall for {{ ppm_app.user }}
{% for redirect in ppm_app.firewall_redirect | default([]) %}
# Redirect {{ redirect.from }} to {{ redirect.to }} ({{ redirect.proto | default('tcp') }})
iptables -A INPUT -p {{ redirect.proto | default('tcp') }} --dport {{ redirect.from }} -j ACCEPT
ip6tables -A INPUT -p {{ redirect.proto | default('tcp') }} --dport {{ redirect.from }} -j ACCEPT
iptables -t nat -A PREROUTING -p {{ redirect.proto | default('tcp') }} --dport {{ redirect.to }} -j REDIRECT --to-ports {{ redirect.from }}
ip6tables -t nat -A PREROUTING -p {{ redirect.proto | default('tcp') }} --dport {{ redirect.to }} -j REDIRECT --to-ports {{ redirect.from }}
{% endfor %}
{% for openport in ppm_app.firewall_openport | default([]) %}
# Open port {{ openport.port }} ({{ openport.proto | default('tcp') }})
iptables -A INPUT -p {{ openport.proto | default('tcp') }} --dport {{ openport.port }} -j ACCEPT
ip6tables -A INPUT -p {{ openport.proto | default('tcp') }} --dport {{ openport.port }} -j ACCEPT
{% endfor %}
{% endfor %}