summaryrefslogtreecommitdiff
path: root/roles/goaccess/main.yml
blob: d15239c7b471894aae044b384d9c75e85a687454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
---
- name: Bootstrapping Container

  vars:
    lxc_base: ansible-centos8
    lxc_name: test

  import_playbook: ../common/tasks/lxc.yml

- name: Installing GoAccess

  hosts: test

  vars_files:
    - ../variables.yml

  tasks:

  - name: Ensuring group exists
    group:
      name: "{{ goaccess_user }}"
      state: present

  - name: Creating user and making home directory
    user:
      system: yes
      state: present
      name: "{{ goaccess_user }}"
      groups: "{{ goaccess_user }}"
      home: "{{ goaccess_home }}"

  - block:

    - name: Cloning repository
      git:
        repo: "{{ goaccess_repository }}"
        dest: "{{ goaccess_home }}"
        version: "{{ goaccess_version }}"
        force: yes

    - name: Creating configuration
      shell: autoreconf -fiv
      args:
        chdir: "{{ goaccess_home }}"
        creates: configure

    - name: Configuring application
      shell: ./configure --enable-utf8 --enable-geoip=mmdb --with-openssl
      args:
        chdir: "{{ goaccess_home }}"
        creates: config.status

    - name: Increasing max referrer ignore limit
      lineinfile:
        path: "{{ goaccess_home }}/src/settings.h"
        regexp: '#define MAX_IGNORE_REF         64'
        line: '#define MAX_IGNORE_REF         2000'

    - name: Compiling application
      shell: make
      args:
        chdir: "{{ goaccess_home }}"
        creates: goaccess

    - name: Creating directories
      file:
        path: "{{ goaccess_home }}/{{ item }}"
        state: directory
      with_items:
        - public
        - database
        - database/geoip

    - name: Downloading referrer spam list
      get_url:
        url:  https://raw.githubusercontent.com/matomo-org/referrer-spam-blacklist/master/spammers.txt
        dest: "{{ goaccess_home }}/config"
        mode: '0644'

    - name: Prepend referrer ignore directive
      shell: sed 's/^/ignore-referer /' spammers.txt > spammers-ignore.txt
      args:
        chdir: "{{ goaccess_home }}/config"
        creates: spammers-ignore.txt

    - name: Downloading GeoLite2 city database
      get_url:
        url:  "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key={{ maxmind_geoip2_key }}&suffix=tar.gz"
        dest: "{{ goaccess_home }}/database/geoip/geolite2-city.tar.gz"
        mode: '0644'

    - name: Extracting GeoLite2 city database
      shell: tar -xf geolite2-city.tar.gz --strip 1
      args:
        chdir: "{{ goaccess_home }}/database/geoip"
        creates: config.status
        warn: false
      changed_when: false

    - name: Placing configuration files
      template:
        src: "{{ item | basename }}.j2"
        dest: "{{ goaccess_home }}/{{ item }}"
      with_items:
        - public/favicon.ico
        - config/goaccess.conf.default
        - config/browsers.list
        - config/exclude.list

    - name: Concatenate configuration
      shell: cat goaccess.conf.default spammers-ignore.txt > goaccess.conf
      args:
        chdir: "{{ goaccess_home }}/config"
      changed_when: false

    become: true
    become_user: "{{ goaccess_user }}"

  - name: Placing system files
    template:
      src: "{{ item | basename }}.j2"
      dest: "{{ item }}"
    with_items:
      - /etc/systemd/system/goaccess.service
      - /etc/systemd/system/goaccess.timer
      - /etc/systemd/system/referrer-blacklist.service
      - /etc/systemd/system/referrer-blacklist.timer

  - name: Enabling and starting units
    systemd:
      name: "{{ item }}"
      state: started
      enabled: yes
      daemon_reload: yes
    with_items:
      - goaccess.timer
      - referrer-blacklist.timer

  - name: Running GoAccess
    systemd:
      name: goaccess
      state: started
      daemon_reload: yes