summaryrefslogtreecommitdiff
path: root/roles/fathom/main.yml
blob: 9174bb9f5be8f36a54708558d562d0ddec6e9675 (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
---
- name: Container Setup

  vars:
    lxc_base: ansible-alpine3.11
    lxc_name: fathom

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

- name: Install Fathom Web Analytics
  hosts: fathom

  vars_files:
    - ../variables.yml

  tasks:

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

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

  - name: Installing the required dependencies
    apk:
      state: present
      update_cache: yes
      name:
        - sudo
        - supervisor
        - tar

  - block:

    - name: Downloading and extracting application
      unarchive:
        src: "https://github.com/usefathom/fathom/releases/download/v{{ fathom_version }}/fathom_{{ fathom_version }}_linux_amd64.tar.gz"
        dest: "{{ fathom_home }}"
        remote_src: yes

    - name: Copying the environment file
      copy:
        src: env
        dest: "{{ fathom_home }}/.env"
        mode: '0644'
      register: fathomConfig
    become: true
    become_user: "{{ fathom_user }}"

  - name: Copying supervisord config file
    copy:
      src: supervisord.conf
      dest: /etc/supervisord.conf
      mode: '0644'
    register: supervisorConfig

  - name: Ensuring supervisord has been started and enabled
    service:
      name: supervisord
      state: started
      enabled: yes

  - name: Waiting for supervisor to become active
    wait_for:
      port: 9100

  - name: Restarting supervisord due to config change
    service:
      name: supervisord
      state: restarted
    when: supervisorConfig.changed

  - name: Ensuring application has been started
    supervisorctl:
      name: fathom
      state: started

  - name: Waiting for application to become active
    wait_for:
      port: 9000

  - name: Restarting application due to config change
    supervisorctl:
      name: fathom
      state: restarted
    when: fathomConfig.changed

  - name: Creating fathom username and password
    shell: /opt/fathom/fathom user add --email='test@example.com' --password='fathom'
    args:
      chdir: "{{ fathom_home }}"
      creates: "{{ fathom_home }}/.user_created"