Skip to content

Commit

Permalink
Merge pull request #2 from benjy44/librenms_update
Browse files Browse the repository at this point in the history
librenms_update - Update module
  • Loading branch information
benjy44 authored Nov 11, 2022
2 parents 2a677d0 + 6a4bfa3 commit c0f4bc7
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 115 deletions.
58 changes: 42 additions & 16 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ librenms_packages:
- python3-setuptools
- python3-systemd
- python3-pip

- php-cli
- php-curl
- php-fpm
- php-gd
- php-gmp
- php-json
- php-mbstring
- php-mysql
- php-snmp
- php-xml
- php-zip

mysql_client_package: mysql-client-core-8.0
mysql_install_client: true
# User and group to create with home directory
librenms_user: librenms
librenms_home: /opt/librenms
Expand Down Expand Up @@ -105,21 +118,27 @@ librenms_ignore_mounts_regexp: []
librenms_rrdcached: unix:/var/run/rrdcached.sock
librenms_rrdcached_settings:
- key: WRITE_TIMEOUT
value: 1800
value: "{{ librenms_rrdcached_write_timeout | default(1800) }}"
- key: WRITE_JITTER
value: 1800
value: "{{ librenms_rrdcached_write_jitter | default(1800) }}"
- key: WRITE_THREADS
value: 4
value: "{{ librenms_rrdcached_write_threads | default(4) }}"
- key: BASE_PATH
value: "{{ librenms_home}}/rrd/"
value: "{{ librenms_rrdcached_base_path | default('/etc/librenms/rrd/') }}"
- key: JOURNAL_PATH
value: "{{ librenms_rrdcached_journal_path | default('/var/lib/rrdcached/journal/') }}"
- key: SOCKGROUP
value: librenms
value: "{{ librenms_rrdcached_sockgroup | default('librenms') }}"
- key: SOCKFILE
value: "{{ librenms_rrdcached_sockfile | default('/run/rrdcached.sock') }}"
- key: DAEMON_GROUP
value: librenms
- key: DAEMON_USER
value: librenms
value: "{{ librenms_rrdcached_daemon_group | default('librenms') }}"
- key: BASE_OPTIONS
value: "-B -F -R"
value: "{{ librenms_rrdcached_write_base_options | default('-B -F -R') }}"
- key: PIDFILE
value: "{{ librenms_rrdcached_pidfile | default('/run/rrdcached.pid') }}"
- key: NETWORK_OPTIONS
value: "{{ librenms_rrdcached_network_options | default('') }}"

# The rrdtool version that is used
librenms_rrdtool_version: 1.7.0
Expand All @@ -129,6 +148,7 @@ librenms_config_nets: []
# - 192.168.10.0/24

# snmp configuration
librenms_config_snmp: false
librenms_config_snmp_timeout: 1
librenms_config_snmp_retries: 3
librenms_config_snmp_community: community
Expand Down Expand Up @@ -174,17 +194,18 @@ librenms_nagios_plugins:
librenms_git_tag:

librenms_environment_settings:
- old_line: "^#DB_HOST="
new_line: "DB_HOST=localhost"
- old_line: "^#DB_DATABASE="
- old_line: "^#?DB_HOST="
new_line: "DB_HOST={{ librenms_sql_host | default('localhost')}}"
- old_line: "^#?DB_DATABASE="
new_line: "DB_DATABASE={{ librenms_sql_databases[0].name }}"
- old_line: "^#DB_USERNAME="
- old_line: "^#?DB_USERNAME="
new_line: "DB_USERNAME={{ librenms_sql_users[0].name }}"
- old_line: "^#DB_PASSWORD="
- old_line: "^#?DB_PASSWORD="
new_line: "DB_PASSWORD={{ librenms_sql_db_password }}"
- old_line: "^#APP_URL="
- old_line: "^#?APP_URL="
new_line: "APP_URL=http://{{ librenms_config_mydomain }}"

librenms_custom_env:
librenms_custom_config:

librenms_install_mysql: true
Expand Down Expand Up @@ -215,3 +236,8 @@ librenms_socialite_saml_plugin_settings:
# metadata:

librenms_postinst_config: []

# Don't run everything on pollers
librenms_poller_only: false

librenms_webserver: apache2
4 changes: 2 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
# handlers file for ansible-role-librenms
- name: restart apache
- name: restart webserver
service:
name: "apache2"
name: "{{ librenms_webserver }}"
state: "restarted"

- name: restart rrdcached
Expand Down
76 changes: 0 additions & 76 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,6 @@ dependencies:
when: librenms_install_mysql | default(false, true)
tags: mysql

# - role: geerlingguy.php
# vars:
# php_enable_php_fpm: true
# php_fpm_state: started
# php_fpm_enabled_on_boot: true
# php_fpm_handler_state: restarted
# php_fpm_pools:
# - pool_name: librenms
# pool_template: www.conf.j2
# pool_listen: "/run/php-fpm-librenms.sock"
# pool_listen_allowed_clients: "127.0.0.1"
# pool_pm: dynamic
# pool_pm_max_children: 5
# pool_pm_start_servers: 2
# pool_pm_min_spare_servers: 1
# pool_pm_max_spare_servers: 3
# pool_pm_max_requests: 500
# php_fpm_pool_user: "{{ librenms_user }}"
# php_fpm_pool_group: "{{ librenms_group }}"
# php_date_timezone: "Europe/Stockholm"
# php_packages_extra:
# - php7.4-gmp
# - php7.4-mysql
# - php7.4-snmp
# - php7.4-zip
# when: librenms_install_php | default(false, true)
# tags: php

- role: geerlingguy.apache
vars:
apache_remove_default_vhost: true
Expand Down Expand Up @@ -104,54 +76,6 @@ dependencies:
- not librenms_install_varnish
tags: apache

- role: geerlingguy.apache
vars:
apache_remove_default_vhost: true
apache_allow_override: "All"
apache_options: "-Indexes +FollowSymLinks"
apache_mods_enabled:
- proxy_fcgi
- setenvif
- rewrite
- proxy
- ssl
- headers
- proxy_http
apache_listen_port: 8080
apache_vhosts:
- servername: "{{ ansible_fqdn }}"
documentroot: "{{ librenms_home }}/html/"
extra_parameters: |
AllowEncodedSlashes NoDecode
<Directory "{{ librenms_home }}/html/">
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
</Directory>
# Enable http authorization headers
<IfModule setenvif_module>
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
</IfModule>
<FilesMatch ".+\.php$">
SetHandler "proxy:unix:/run/php-fpm-librenms.sock|fcgi://localhost"
</FilesMatch>
apache_vhosts_ssl:
- servername: "{{ ansible_fqdn }}"
certificate_file: "/etc/ssl/certs/ssl-cert-snakeoil.pem"
certificate_key_file: "/etc/ssl/private/ssl-cert-snakeoil.key"
extra_parameters: |
RequestHeader set X-Forwarded-Proto "https"
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:80/
ProxyPassReverse / http://127.0.0.1:80/
when:
- librenms_install_apache | default(false, true)
- librenms_install_varnish
tags: apache

- role: ansible-role-snmp
vars:
snmp_install: true
Expand Down
31 changes: 29 additions & 2 deletions tasks/librenms-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@
with_items: "{{ librenms_environment_settings }}"
no_log: true

- name: Update app key settings in "{{ librenms_home }}/.env"
lineinfile:
path: "{{ librenms_home }}/.env"
regex: "APP_KEY="
line: "APP_KEY={{ librenms_environment_settings_app_key }}"
no_log: true
when: librenms_environment_settings_app_key is defined

- name: Set additional env settings in "{{ librenms_home }}/.env"
lineinfile:
path: "{{ librenms_home }}/.env"
regex: "{{ item.old_line }}"
line: "{{ item.new_line }}"
with_items: "{{ librenms_custom_env }}"
when: (librenms_custom_env is defined) and (librenms_custom_env|length > 0)
no_log: true

- name: Set redis settings in "{{ librenms_home }}/.env"
lineinfile:
path: "{{ librenms_home }}/.env"
regex: "{{ item.old_line }}"
line: "{{ item.new_line }}"
with_items: "{{ librenms_environment_redis }}"
when: (librenms_environment_redis is defined) and (librenms_environment_redis|length > 0)
no_log: true

- name: Build DB
become: True
become_user: "{{ librenms_user }}"
Expand All @@ -19,6 +45,7 @@
changed_when: "'Nothing to migrate.' not in build_db.stdout"
tags:
- build_db
when: not librenms_poller_only

- name: Create admin user and password.
command: "./adduser.php {{ librenms_admin_user }} {{ librenms_admin_password }} 10"
Expand All @@ -30,6 +57,7 @@
changed_when: "'User admin already exists!' not in librenms_admin_user.stdout"
tags:
- librenms_admin_user
when: not librenms_poller_only

- name: Deploy config.php
template:
Expand All @@ -41,7 +69,7 @@
tags:
- config.php
notify:
- restart apache
- restart webserver

- name: Delete "INSTALL=true" in "{{ librenms_home }}/.env"
lineinfile:
Expand Down Expand Up @@ -84,4 +112,3 @@
become: true
tags:
- logrotate

9 changes: 0 additions & 9 deletions tasks/librenms-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,3 @@
dest: /etc/bash_completion.d/
tags:
- lnms

#- name: Update running daily.sh. # noqa 301
# command: "./daily.sh"
# args:
# chdir: "{{ librenms_home }}"
# become_user: "{{ librenms_user }}"
# become: yes
# tags:
# - run_daily.sh
1 change: 0 additions & 1 deletion tasks/librenms-postinst.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
tags:
- librenms
- librenms_postinst

1 change: 1 addition & 0 deletions tasks/librenms-socialite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
tags:
- librenms_socialite
- librenms_socialite_microsoft_plugin_settings
no_log: true

- name: Install Socialite SAML plugin
become: yes
Expand Down
2 changes: 2 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import_tasks: rrdcached.yml
tags:
- rrdcached
when: not librenms_poller_only

- name: Install nagios plugins.
import_tasks: nagios_plugins.yml
Expand All @@ -38,6 +39,7 @@
tags:
- librenms_socialite
- librenms
when: not librenms_poller_only

- name: LibreNMS postinst configuration
import_tasks: librenms-postinst.yml
Expand Down
8 changes: 8 additions & 0 deletions tasks/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@
cache_valid_time: 3600
when: ansible_architecture == "x86_64" and
ansible_distribution == "Ubuntu"

- name: install MySQL Client
apt:
name: "{{ mysql_client_package }}"
cache_valid_time: 3600
when: ansible_architecture == "x86_64" and
ansible_distribution == "Ubuntu" and
mysql_install_client == true
18 changes: 17 additions & 1 deletion tasks/rrdcached.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- name: Update /etc/default/rrdcached
lineinfile:
path: "/etc/default/rrdcached"
regex: '^#*\s*{{ item.key }}.*$'
regex: '^#?{{ item.key }}'
line: "{{ item.key }}={{ item.value }}"
with_items: "{{ librenms_rrdcached_settings }}"
when: ansible_architecture == "x86_64" and
Expand All @@ -24,6 +24,22 @@
- rrdcached
- rrdcached_configure

- name: Update /etc/default/rrdcached - custom settings
lineinfile:
path: "/etc/default/rrdcached"
regex: '^#?{{ item.key }}'
line: "{{ item.key }}={{ item.value }}"
with_items: "{{ librenms_rrdcached_settings_custom }}"
when: ansible_architecture == "x86_64" and
ansible_os_family == "Debian" and
librenms_rrdcached is defined and
librenms_rrdcached_settings_custom is defined
notify:
- restart rrdcached
tags:
- rrdcached
- rrdcached_configure

- name: Change ownership on /var/lib/rrdcached/
file:
path: "/var/lib/rrdcached"
Expand Down
4 changes: 2 additions & 2 deletions tasks/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
system: yes
state: present
notify:
- restart apache
- restart webserver

- name: Add www-data to librenms group.
user:
Expand All @@ -24,4 +24,4 @@
- www-data
- "{{ librenms_group }}"
notify:
- restart apache
- restart webserver
Loading

0 comments on commit c0f4bc7

Please sign in to comment.