diff --git a/defaults/main.yml b/defaults/main.yml index c42f3a6..8803729 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -14,7 +14,7 @@ userli_wkd_directory: "/var/www/html" userli_wkd_format: "advanced" # or 'advanced' or 'direct' # to trigger a deployment or initial rollout use "-e userli_update=True" in command line -userli_update: false +userli_update: False # extra reserved local parts userli_extra_reserved_names: [] @@ -31,10 +31,14 @@ userli_env_vars: - name: WKD_FORMAT value: "{{ userli_wkd_format }}" +userli_prometheus_textfile_collector_enabled: False +userli_prometheus_textfile_collector_path: "/var/lib/prometheus/node-exporter" +userli_prometheus_textfile_collector_on_calendar: "*-*-* *:*:00" + # munin integration -userli_munin: false +userli_munin: False -userli_primary: true +userli_primary: True userli_webserver: apache2 # Set default language for navbar diff --git a/handlers/main.yml b/handlers/main.yml index ef01614..550a4b1 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -26,3 +26,15 @@ ansible.builtin.service: name: "{{ userli_webserver }}" state: restarted + +- name: Reload systemd daemon + ansible.builtin.systemd: + daemon_reload: true + +- name: Restart userli-collector + ansible.builtin.service: + name: "{{ item }}" + state: restarted + loop: + - userli-collector.service + - userli-collector.timer diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index d9bf0dc..d2a349e 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -1,5 +1,4 @@ --- - - name: Converge hosts: all become: true diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 1bc35ac..9ed4f46 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -4,13 +4,12 @@ become: true pre_tasks: - name: Run the equivalent of "apt-get update" before installing packages - apt: + ansible.builtin.apt: update_cache: yes - name: Install cron for testing in docker containers - apt: + ansible.builtin.apt: pkg: cron - update_cache: yes roles: - weareinteractive.apt - geerlingguy.apache @@ -25,7 +24,7 @@ extra_parameters: | SetEnv APP_ENV prod apt_packages: - - acl # support for unpriviledged become_user + - acl # support for unpriviledged become_user - unzip php_default_version_debian: "{% if ansible_distribution_release == 'bullseye' %}7.4{% else %}8.2{% endif %}" php_packages: diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml index 198ca50..3960c2e 100644 --- a/molecule/default/requirements.yml +++ b/molecule/default/requirements.yml @@ -1,5 +1,4 @@ --- - roles: - name: weareinteractive.apt - name: geerlingguy.apache diff --git a/requirements.yml b/requirements.yml index 9cb8cca..d45f806 100644 --- a/requirements.yml +++ b/requirements.yml @@ -1,5 +1,4 @@ --- - collections: - community.general - community.mysql diff --git a/tasks/main.yml b/tasks/main.yml index f7ff862..15895e1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -103,4 +103,7 @@ - name: Import Munin tasks ansible.builtin.import_tasks: munin.yml when: userli_munin | bool - tags: munin + +- name: Import metrics tasks + ansible.builtin.import_tasks: metrics.yml + when: userli_prometheus_textfile_collector_enabled | bool diff --git a/tasks/metrics.yml b/tasks/metrics.yml new file mode 100644 index 0000000..0f14ca6 --- /dev/null +++ b/tasks/metrics.yml @@ -0,0 +1,23 @@ +--- +- name: Copy Textfile Collector Service + ansible.builtin.template: + src: "{{ item }}.j2" + dest: "/etc/systemd/system/{{ item }}" + owner: root + group: root + mode: 0644 + notify: + - Reload systemd daemon + - Restart userli-collector + loop: + - userli-collector.service + - userli-collector.timer + +- name: Enable Textfile Collector Service + ansible.builtin.systemd: + name: "{{ item }}" + enabled: yes + state: started + loop: + - userli-collector.service + - userli-collector.timer diff --git a/templates/userli-collector.service.j2 b/templates/userli-collector.service.j2 new file mode 100644 index 0000000..693ba81 --- /dev/null +++ b/templates/userli-collector.service.j2 @@ -0,0 +1,12 @@ +[Unit] +Description=Userli Prometheus Textfile Collector +After=systemd-modules-load.service +DefaultDependencies=no + +[Service] +Type=oneshot +ExecStart=/bin/bash -c 'php {{ userli_symfony_path }}/bin/console app:metrics | sponge {{ userli_prometheus_textfile_collector_path }}/userli.prom' +SyslogIdentifier=userli-textfile-collector + +[Install] +WantedBy=multi-user.target diff --git a/templates/userli-collector.timer.j2 b/templates/userli-collector.timer.j2 new file mode 100644 index 0000000..d7b2e9d --- /dev/null +++ b/templates/userli-collector.timer.j2 @@ -0,0 +1,9 @@ +[Unit] +Description=Userli Prometheus Textfile Collector Timer + +[Timer] +OnCalendar={{ userli_prometheus_textfile_collector_on_calendar }} +Persistent=true + +[Install] +WantedBy=timers.target