summaryrefslogtreecommitdiff
path: root/roles/scag/tasks/main.yml
blob: ca26c3e940c65476af3b3b53d45cc4ec03a0d783 (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
- name: Install scag by pre-compiling the binary
  when: ( not ( scag_install_method is defined ) ) or scag_install_method == "precompile"
  block:
    - name: Fetch scag source code
      delegate_to: 127.0.0.1
      become: false
      ansible.builtin.git:
        repo: https://git.joeac.net/scag.git
        dest: /tmp/scag
        depth: 1
    - name: Cross-compile scag
      delegate_to: 127.0.0.1
      become: false
      ansible.builtin.shell:
        cmd: cross build --release --target {{ rust_target }}
        chdir: /tmp/scag
      changed_when: "'Compiling' in _task.result.stderr"
    - name: Install scag binary
      ansible.builtin.copy:
        src: /tmp/scag/target/{{ rust_target }}/release/scag
        dest: /usr/bin/scag
        mode: +x

- name: Install or update scag using rustup
  when: scag_install_method == "rustup"
  block:
    - name: Install Rust toolchain using installation script
      ansible.builtin.shell:
        cmd: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
        creates: /usr/bin/rustc
    - name: Update Rust toolchain with rustup
      ansible.builtin.shell: rustup update
      changed_when: "'updated' in _task.result.stdout"
    - name: Install or update scag using cargo
      ansible.builtin.shell:
        cmd: cargo install --git git://git.joeac.net/scag.git
      changed_when: "'Installed' in _task.result.stdout or 'Replaced' in _task.result.stdout"
    - name: Install daily crontab to update scag using cargo
      ansible.builtin.cron:
        special_time: daily
        name: Update scag
        job: cargo install --git git://git.joeac.net/scag.git

- name: Install scag using cargo provided by APK
  when: scag_install_method == "cargo"
  block:
    - name: Install cargo using APK
      community.general.apk:
        name: cargo
    - name: Install or update scag using cargo
      ansible.builtin.shell:
        cmd: cargo install --git git://git.joeac.net/scag.git
      changed_when: "'Installed' in _task.result.stdout or 'Replaced' in _task.result.stdout"
    - name: Install daily crontab to update scag using cargo
      ansible.builtin.cron:
        special_time: daily
        name: Update scag
        job: cargo install --git git://git.joeac.net/scag.git

- name: Create scag configuration directory
  ansible.builtin.file:
    path: /etc/scag
    state: directory

- name: Configure scag
  ansible.builtin.template:
    src: scag.toml
    dest: /etc/scag/config.toml

- name: Configure HTML feed head
  ansible.builtin.shell:
    cmd: |
      curl --silent https://git.joeac.net/joeac.net.git/plain/http/share/components/head.upphtml \
        | grep -E ^\<link\ rel=\"stylesheet\" \
        > {{ feed_html_head }}
    creates: "{{ feed_html_head }}"

- name: Configure HTML feed header
  ansible.builtin.template:
    src: header.html
    dest: "{{ feed_html_header }}"

- name: Fetch subscriptions
  ansible.builtin.git:
    repo: git://git.joeac.net/subscriptions.git
    dest: "{{ src_dir }}/subscriptions"
    depth: 1

- name: Symlink subscriptions into scag configuration directory
  ansible.builtin.file:
    src: "{{ src_dir }}/subscriptions/subscriptions.txt"
    dest: /etc/scag/subscriptions.txt
    state: link

- name: Create directory for RSS file
  ansible.builtin.file:
    path: "{{ http_files_dir }}/feed/{{ feed_dir }}"
    state: directory
    owner: nginx
    group: nginx

- name: Use scag to generate RSS file
  ansible.builtin.shell:
    cmd: scag
    creates: "{{ http_files_dir }}/feed/{{ feed_rss_path }}"

- name: Install nginx location config
  register: nginx_conf
  ansible.builtin.template:
    src: nginx/feed.conf
    dest: /etc/nginx/http.d/joeac.net.locations.d/feed.conf

- name: Restart nginx
  when: nginx_conf is changed
  ansible.builtin.service:
    name: nginx
    state: restarted

- name: Install hourly crontab to update subscriptions and run scag
  ansible.builtin.cron:
    special_time: daily
    name: Run scag
    job: >-
      git -C "{{ src_dir }}/subscriptions" pull;
      scag