#####################################
### someone"s ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2025 by someone <someone@somenet.org>
#
# Install munin-node and munin-async.
#
---
- name: install munin
  apt:
    pkg:
    - munin
    state: present
    policy_rc_d: 101
  tags: "online"


- name: copy munin.conf to /etc/munin/munin.conf
  copy:
    src: "{{item}}"
    dest: "/etc/munin/munin.conf"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/munin.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/munin.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/munin.conf"
    - "default/munin.conf"


- name: create .ssh-dir
  file:
    path: "/var/lib/munin/.ssh"
    state: directory
    mode: 0700
    owner: "munin"
    group: "munin"


- name: copy id_ed25519 to /var/lib/munin/.ssh/id_ed25519
  copy:
    src: "{{item}}"
    dest: "/var/lib/munin/.ssh/id_ed25519"
    mode: 0600
    owner: "munin"
    group: "munin"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/id_ed25519"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/id_ed25519"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/id_ed25519"
    - "default/id_ed25519"


- name: include vars_nginx_vhost_custom
  include_vars:
    file: "{{item}}"
    name: vars_nginx_vhost_custom
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/{{munin_domain}}-vars_nginx_vhost_custom.yml"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/{{munin_domain}}-vars_nginx_vhost_custom.yml"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/{{munin_domain}}-vars_nginx_vhost_custom.yml"
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/vars_nginx_vhost_custom.yml"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/vars_nginx_vhost_custom.yml"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/vars_nginx_vhost_custom.yml"
    - "default/vars_nginx_vhost_custom.yml"


- name: configure munin vhost
  include_role:
    name: server/nginx/vhost-unified
  vars:
    vhost_type: "custom"
    vhost_name: "{{munin_domain}}"
    vhost_custom:
      vhost_custom_pre_server: "{{vars_nginx_vhost_custom.vhost_custom_pre_server}}"
      vhost_custom: "{{vars_nginx_vhost_custom.vhost_custom}}"
