summaryrefslogtreecommitdiff
path: root/roles
diff options
context:
space:
mode:
Diffstat (limited to 'roles')
-rw-r--r--roles/http/tasks/main.yml5
-rw-r--r--roles/http/templates/nginx/joeac.net.conf2
-rw-r--r--roles/rss-aggregator/tasks/main.yml112
-rw-r--r--roles/rss-aggregator/templates/nginx/feed.conf4
-rw-r--r--roles/rss-aggregator/templates/rss-aggregator.toml3
5 files changed, 126 insertions, 0 deletions
diff --git a/roles/http/tasks/main.yml b/roles/http/tasks/main.yml
index 9d2ae22..4907c55 100644
--- a/roles/http/tasks/main.yml
+++ b/roles/http/tasks/main.yml
@@ -40,6 +40,11 @@
src: nginx/joeac.net.conf
dest: /etc/nginx/http.d/joeac.net.conf
+- name: Create joeac.net locations config directory
+ ansible.builtin.file:
+ path: /etc/nginx/http.d/joeac.net.locations.d
+ state: directory
+
- name: Restart nginx service if config changed
when: joeacnet_nginx_site_config is changed
ansible.builtin.service:
diff --git a/roles/http/templates/nginx/joeac.net.conf b/roles/http/templates/nginx/joeac.net.conf
index 9f28fee..0cf7a1f 100644
--- a/roles/http/templates/nginx/joeac.net.conf
+++ b/roles/http/templates/nginx/joeac.net.conf
@@ -21,4 +21,6 @@ server {
location ~ /\.sqlite {
deny all;
}
+
+ include /etc/nginx/http.d/joeac.net.locations.d/*.conf;
}
diff --git a/roles/rss-aggregator/tasks/main.yml b/roles/rss-aggregator/tasks/main.yml
new file mode 100644
index 0000000..9e23ca3
--- /dev/null
+++ b/roles/rss-aggregator/tasks/main.yml
@@ -0,0 +1,112 @@
+- name: Install rss-aggregator by pre-compiling the binary
+ when: ( not ( rss_aggregator_install_method is defined ) ) or rss_aggregator_install_method == "precompile"
+ block:
+ - name: Fetch rss-aggregator source code
+ delegate_to: 127.0.0.1
+ become: false
+ ansible.builtin.git:
+ repo: https://git.joeac.net/rss-aggregator.git
+ dest: /tmp/rss-aggregator
+ depth: 1
+ - name: Cross-compile rss-aggregator
+ delegate_to: 127.0.0.1
+ become: false
+ ansible.builtin.shell:
+ cmd: cross build --release --target {{ rust_target }}
+ chdir: /tmp/rss-aggregator
+ changed_when: "'Compiling' in _task.result.stderr"
+ - name: Install rss-aggregator binary
+ ansible.builtin.copy:
+ src: /tmp/rss-aggregator/target/{{ rust_target }}/release/rss-aggregator
+ dest: /usr/bin/rss-aggregator
+ mode: +x
+
+- name: Install or update rss-aggregator using rustup
+ when: rss_aggregator_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 rss-aggregator using cargo
+ ansible.builtin.shell:
+ cmd: cargo install --git git://git.joeac.net/rss-aggregator.git
+ changed_when: "'Installed' in _task.result.stdout or 'Replaced' in _task.result.stdout"
+ - name: Install daily crontab to update rss-aggregator using cargo
+ ansible.builtin.cron:
+ special_time: daily
+ name: Update rss-aggregator
+ job: cargo install --git git://git.joeac.net/rss-aggregator.git
+
+- name: Install rss-aggregator using cargo provided by APK
+ when: rss_aggregator_install_method == "cargo"
+ block:
+ - name: Install cargo using APK
+ community.general.apk:
+ name: cargo
+ - name: Install or update rss-aggregator using cargo
+ ansible.builtin.shell:
+ cmd: cargo install --git git://git.joeac.net/rss-aggregator.git
+ changed_when: "'Installed' in _task.result.stdout or 'Replaced' in _task.result.stdout"
+ - name: Install daily crontab to update rss-aggregator using cargo
+ ansible.builtin.cron:
+ special_time: daily
+ name: Update rss-aggregator
+ job: cargo install --git git://git.joeac.net/rss-aggregator.git
+
+- name: Create rss-aggregator configuration directory
+ ansible.builtin.file:
+ path: /etc/rss-aggregator
+ state: directory
+
+- name: Configure rss-aggregator
+ ansible.builtin.template:
+ src: rss-aggregator.toml
+ dest: /etc/rss-aggregator/config.toml
+
+- name: Fetch subscriptions
+ ansible.builtin.git:
+ repo: git://git.joeac.net/subscriptions.git
+ dest: "{{ src_dir }}/subscriptions"
+ depth: 1
+
+- name: Symlink subscriptions into rss-aggregator configuration directory
+ ansible.builtin.file:
+ src: "{{ src_dir }}/subscriptions/subscriptions.txt"
+ dest: /etc/rss-aggregator/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 rss-aggregator to generate RSS file
+ ansible.builtin.shell:
+ cmd: rss-aggregator > {{ http_files_dir }}/feed/{{ feed_rss_path }}
+ 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 rss-aggregator
+ ansible.builtin.cron:
+ special_time: daily
+ name: Run rss-aggregator
+ job: >-
+ git -C "{{ src_dir }}/subscriptions" pull;
+ rss-aggregator > {{ http_files_dir }}/feed/{{ feed_rss_path }}
diff --git a/roles/rss-aggregator/templates/nginx/feed.conf b/roles/rss-aggregator/templates/nginx/feed.conf
new file mode 100644
index 0000000..6f650ba
--- /dev/null
+++ b/roles/rss-aggregator/templates/nginx/feed.conf
@@ -0,0 +1,4 @@
+location /feed {
+ root {{ http_files_dir }}/feed;
+ try_files $uri $uri.xml $uri.rss $uri.atom $uri.rss.xml $uri.html $uri/index.html $uri.php $uri/index.php =404;
+}
diff --git a/roles/rss-aggregator/templates/rss-aggregator.toml b/roles/rss-aggregator/templates/rss-aggregator.toml
new file mode 100644
index 0000000..22a8f72
--- /dev/null
+++ b/roles/rss-aggregator/templates/rss-aggregator.toml
@@ -0,0 +1,3 @@
+title = "Stuff that Joe Carstairs wants to read"
+description = "Stuff that Joe Carstairs wants to read"
+link = "https://joeac.net/{{ feed_rss_path }}"