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


- name: create inspircd user's homedir
  file:
    path: "/var/lib/inspircd"
    state: directory
    mode: 0710
    owner: "irc"
    group: "irc"


- name: add irc user to group ssl-cert,letsencrypt
  user:
    name: "cyrus"
    groups: "ssl-cert,letsencrypt"
    append: yes
    createhome: no
    state: present


- name: create inspircd config dir
  file:
    path: "/etc/inspircd"
    state: directory
    mode: 0750
    owner: "irc"
    group: "irc"


- name: copy irc server config files
  copy:
    src:  "{{item.src}}"
    dest: "/etc/inspircd/{{item.path}}"
    mode: 0640
    owner: "irc"
    group: "irc"
  with_filetree:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/inspircd/"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/inspircd/"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/inspircd/"
    - "default/inspircd/"
  when: item.state == "file"
  notify: reload inspircd.service


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


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