--- /dev/null
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+- hosts: servers
+ vars:
+ dest: "{{ ansible_local.env.vars.prod_dir }}/payments"
+ repo: "{{ ansible_local.env.vars.git_home_dir }}/payments.git"
+ site: payments.conf
+ tasks:
+ - name: Create destination directory
+ file:
+ path: "{{ dest }}"
+ state: directory
+ mode: 0775
+ owner: git
+ group: www-data
+ become: true
+ - name: Checkout scripts to the destination directory
+ command: git --work-tree={{ dest }} --git-dir={{ repo }} checkout main \
+ --force *.sh
+ become: true
+ - find:
+ paths: "{{ dest }}"
+ file_type: file
+ patterns: "*.sh"
+ register: scripts
+ - name: Make payments scripts executable
+ file:
+ path: "{{ item.path }}"
+ mode: 0744
+ owner: www-data
+ group: www-data
+ become: true
+ with_items: "{{ scripts.files }}"
+
+ - name: Install fcgiwrap and nginx
+ package:
+ name:
+ - fcgiwrap
+ - nginx
+ state: latest
+ become: true
+ - name: Checkout site to /etc/nginx/sites-available
+ command: git --work-tree=/etc/nginx/sites-available --git-dir={{ repo }} \
+ checkout main --force {{ site }}
+ become: true
+ - name: Enable site in nginx
+ shell: envsubst < /etc/nginx/sites-available/{{ site }} \
+ > /etc/nginx/sites-enabled/{{ site }}
+ environment: "{{ ansible_local.env.vars }}"
+ become: true
+ - name: Restart fcgiwrap and nginx
+ service:
+ name: "{{ item }}"
+ state: restarted
+ become: true
+ with_items:
+ - fcgiwrap
+ - nginx
--- /dev/null
+#!/bin/sh
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+while read old_revision new_revision branch
+do
+ if [ "${branch}" != "refs/heads/main" ]
+ then
+ echo "${branch} is not the main branch so not deploying."
+ exit 0
+ fi
+ sudo ansible-playbook --connection=local deploy.yaml
+done