diff --git a/defaults/main.yml b/defaults/main.yml index 38e1e52..74247c9 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/handlers/main.yml b/handlers/main.yml index e7cd08b..900f96c 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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 diff --git a/meta/main.yml b/meta/main.yml index b112c69..c47e1fc 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -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 @@ -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 - - Require all granted - AllowOverride All - Options FollowSymLinks MultiViews - - - # Enable http authorization headers - - SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1 - - - - SetHandler "proxy:unix:/run/php-fpm-librenms.sock|fcgi://localhost" - - - 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 diff --git a/tasks/librenms-config.yml b/tasks/librenms-config.yml index bc6bad2..5370cb1 100644 --- a/tasks/librenms-config.yml +++ b/tasks/librenms-config.yml @@ -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 }}" @@ -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" @@ -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: @@ -41,7 +69,7 @@ tags: - config.php notify: - - restart apache + - restart webserver - name: Delete "INSTALL=true" in "{{ librenms_home }}/.env" lineinfile: @@ -84,4 +112,3 @@ become: true tags: - logrotate - diff --git a/tasks/librenms-install.yml b/tasks/librenms-install.yml index 62bb796..c55b993 100644 --- a/tasks/librenms-install.yml +++ b/tasks/librenms-install.yml @@ -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 diff --git a/tasks/librenms-postinst.yml b/tasks/librenms-postinst.yml index 8f10dae..6d004ec 100644 --- a/tasks/librenms-postinst.yml +++ b/tasks/librenms-postinst.yml @@ -12,4 +12,3 @@ tags: - librenms - librenms_postinst - diff --git a/tasks/librenms-socialite.yml b/tasks/librenms-socialite.yml index a682884..a8b285b 100644 --- a/tasks/librenms-socialite.yml +++ b/tasks/librenms-socialite.yml @@ -50,6 +50,7 @@ tags: - librenms_socialite - librenms_socialite_microsoft_plugin_settings + no_log: true - name: Install Socialite SAML plugin become: yes diff --git a/tasks/main.yml b/tasks/main.yml index e774038..63f1d35 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -20,6 +20,7 @@ import_tasks: rrdcached.yml tags: - rrdcached + when: not librenms_poller_only - name: Install nagios plugins. import_tasks: nagios_plugins.yml @@ -38,6 +39,7 @@ tags: - librenms_socialite - librenms + when: not librenms_poller_only - name: LibreNMS postinst configuration import_tasks: librenms-postinst.yml diff --git a/tasks/packages.yml b/tasks/packages.yml index 48643df..2d6a2c3 100644 --- a/tasks/packages.yml +++ b/tasks/packages.yml @@ -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 diff --git a/tasks/rrdcached.yml b/tasks/rrdcached.yml index 6506337..55474c3 100644 --- a/tasks/rrdcached.yml +++ b/tasks/rrdcached.yml @@ -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 @@ -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" diff --git a/tasks/user.yml b/tasks/user.yml index ee17d49..08051e0 100644 --- a/tasks/user.yml +++ b/tasks/user.yml @@ -15,7 +15,7 @@ system: yes state: present notify: - - restart apache + - restart webserver - name: Add www-data to librenms group. user: @@ -24,4 +24,4 @@ - www-data - "{{ librenms_group }}" notify: - - restart apache + - restart webserver diff --git a/templates/opt/librenms/config.php.j2 b/templates/opt/librenms/config.php.j2 index c65b709..3e1d062 100644 --- a/templates/opt/librenms/config.php.j2 +++ b/templates/opt/librenms/config.php.j2 @@ -24,17 +24,19 @@ $config['rrdtool_version'] = "{{ librenms_rrdtool_version }}"; ### Update configuration $config['update_channel'] = 'release'; # uncomment to follow the monthly release channel +{% if librenms_config_snmp %} ### SNMP configuration $config['snmp']['community'] = array("{{ librenms_config_snmp_community }}"); $config['snmp']['timeout'] = {{ librenms_config_snmp_timeout }}; $config['snmp']['retries'] = {{ librenms_config_snmp_retries }}; $config['snmp']['version'] = ['v3', 'v2c', 'v1']; -$config['snmp']['v3'][1]['authlevel'] = "{{ librenms_config_snmp_authlevel | mandatory }}"; -$config['snmp']['v3'][1]['authname'] = "{{ librenms_config_snmp_authname | mandatory }}"; -$config['snmp']['v3'][1]['authpass'] = "{{ librenms_config_snmp_authpass | mandatory }}"; +$config['snmp']['v3'][1]['authlevel'] = "{{ librenms_config_snmp_authlevel }}"; +$config['snmp']['v3'][1]['authname'] = "{{ librenms_config_snmp_authname }}"; +$config['snmp']['v3'][1]['authpass'] = "{{ librenms_config_snmp_authpass }}"; $config['snmp']['v3'][1]['authalgo'] = "{{ librenms_config_snmp_authalgo | default("MD5", true) }}"; -$config['snmp']['v3'][1]['cryptopass'] = "{{ librenms_config_snmp_cryptopass | mandatory }}"; +$config['snmp']['v3'][1]['cryptopass'] = "{{ librenms_config_snmp_cryptopass }}"; $config['snmp']['v3'][1]['cryptoalgo'] = "{{ librenms_config_snmp_cryptoalgo | default("DES", true) }}"; +{% endif %} ### Ignore interfaces {% for librenms_config_bad_if_regexp in librenms_config_bad_if_regexps %} @@ -42,9 +44,11 @@ $config['bad_if_regexp'][] = '{{ librenms_config_bad_if_regexp }}'; {% endfor %} ### Auto Discovery configuration +{% if librenms_config_nets is defined %} {% for librenms_config_net in librenms_config_nets %} -# $config['nets'][] = "{{ librenms_config_net }}"; +$config['nets'][] = "{{ librenms_config_net }}"; {% endfor %} +{% endif %} $config['auth_mechanism'] = '{{ librenms_config_auth_mechanism }}'; {% if librenms_config_ldap %} @@ -103,7 +107,12 @@ $config['influxdb']['timeout'] = 0; $config['influxdb']['verifySSL'] = false; {% endif %} +{%- if librenms_distributed_poller is defined %} +{% for key, value in librenms_distributed_poller %} +$config["{{ key }}"] = "{{ value }}"; +{% endfor %} +{% endif %} + {%- if librenms_custom_config | default(None) %} {{ librenms_custom_config }} {% endif %} -