#####################################
### someone"s ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2025 by someone <someone@somenet.org>
#
---
- name: install anope irc services
  apt:
    pkg:
    - anope
    state: present
    policy_rc_d: 101
  tags: "online"
  ignore_errors: "{{ignore_online_errors | bool}}"


- name: create anope user
  user:
    name: "anope"
    home: "/srv/anope"
    shell: "/bin/bash"
    createhome: no
    system: yes
    state: present


- name: create anope user's homedir
  file:
    path: "/srv/anope"
    state: directory
    mode: 0710
    owner: "anope"
    group: "anope"


- name: create anope-db dir
  file:
    path: "/srv/anope/db"
    state: directory
    mode: 0750
    owner: "anope"
    group: "anope"


- name: create anope-db-backup dir
  file:
    path: "/srv/anope/db/backups"
    state: directory
    mode: 0750
    owner: "anope"
    group: "anope"


- name: create anope logdir
  file:
    path: "/var/log/anope"
    state: directory
    mode: 0750
    owner: "anope"
    group: "anope"


- name: copy chanserv.conf config
  copy:
    src: "{{item}}"
    dest: "/etc/anope/chanserv.conf"
    mode: 0640
    owner: "anope"
    group: "anope"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/chanserv.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/chanserv.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/chanserv.conf"
    - "default/chanserv.conf"
  notify: reload anope.service


- name: copy global.conf config
  copy:
    src: "{{item}}"
    dest: "/etc/anope/global.conf"
    mode: 0640
    owner: "anope"
    group: "anope"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/global.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/global.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/global.conf"
    - "default/global.conf"
  notify: reload anope.service


- name: copy hostserv.conf config
  copy:
    src: "{{item}}"
    dest: "/etc/anope/hostserv.conf"
    mode: 0640
    owner: "anope"
    group: "anope"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/hostserv.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/hostserv.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/hostserv.conf"
    - "default/hostserv.conf"
  notify: reload anope.service


- name: copy memoserv.conf config
  copy:
    src: "{{item}}"
    dest: "/etc/anope/memoserv.conf"
    mode: 0640
    owner: "anope"
    group: "anope"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/memoserv.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/memoserv.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/memoserv.conf"
    - "default/memoserv.conf"
  notify: reload anope.service


- name: copy modules.conf config
  copy:
    src: "{{item}}"
    dest: "/etc/anope/modules.conf"
    mode: 0640
    owner: "anope"
    group: "anope"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/modules.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/modules.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/modules.conf"
    - "default/modules.conf"
  notify: reload anope.service


- name: copy nickserv.conf config
  copy:
    src: "{{item}}"
    dest: "/etc/anope/nickserv.conf"
    mode: 0640
    owner: "anope"
    group: "anope"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/nickserv.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/nickserv.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/nickserv.conf"
    - "default/nickserv.conf"
  notify: reload anope.service


- name: copy operserv.conf config
  copy:
    src: "{{item}}"
    dest: "/etc/anope/operserv.conf"
    mode: 0640
    owner: "anope"
    group: "anope"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/operserv.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/operserv.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/operserv.conf"
    - "default/operserv.conf"
  notify: reload anope.service


- name: copy services.conf config
  copy:
    src: "{{item}}"
    dest: "/etc/anope/services.conf"
    mode: 0640
    owner: "anope"
    group: "anope"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/services.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/services.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/services.conf"
    - "default/services.conf"
  notify: reload anope.service


- name: copy services.motd config
  copy:
    src: "{{item}}"
    dest: "/etc/anope/services.motd"
    mode: 0640
    owner: "anope"
    group: "anope"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/services.motd"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/services.motd"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/services.motd"
    - "default/services.motd"
  notify: reload anope.service


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


- name: enable and start anope.service
  include_role: name="base/systemd/enable-and-start"
  vars:
    service_name: anope.service
