Skip to content

Commit 3e825bd

Browse files
authored
Merge pull request #4 from QuLogic/ansible
Setup Ansible config for web hosting
2 parents 6af8177 + 134cf2b commit 3e825bd

21 files changed

+17762
-0
lines changed

.github/workflows/lint.yml

+13
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,16 @@ jobs:
5858
with:
5959
fail_on_error: true
6060
tool_name: 'caddy fmt'
61+
62+
ansible:
63+
name: Ansible Lint
64+
runs-on: ubuntu-latest
65+
66+
steps:
67+
- uses: actions/checkout@v3
68+
69+
- name: Set up Python 3
70+
uses: actions/setup-python@v3
71+
72+
- name: ansible-lint
73+
uses: reviewdog/action-ansiblelint@v1

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,37 @@ overrides in environment variables:
4040
interfaces)
4141
* The directory containing the git repositories with `SITE_DIR` (defaults to
4242
`sites` in the current directory)
43+
44+
Ansible configuration
45+
=====================
46+
47+
When running on DigitalOcean hosting, an Ansible playbook is used to configure
48+
the server with consistent settings.
49+
50+
Setup
51+
-----
52+
53+
Before you can run our ansible playbooks, you need to meet the following
54+
prerequisites:
55+
56+
* Create a DigitalOcean API token, and pass it to the inventory generator by
57+
setting the `DO_API_TOKEN` environment variable.
58+
* Set the vault decryption password of the ansible vaulted file with our
59+
secrets. This may be done by setting the `ANSIBLE_VAULT_PASSWORD_FILE`
60+
environment variable to point to a file containing the password.
61+
* Download all the collections the playbooks depend on with the following
62+
command:
63+
```
64+
ansible-galaxy collection install \
65+
--requirements-file collections/requirements.yml
66+
```
67+
68+
You may wish to use [direnv](https://direnv.net/) to set environment variables.
69+
70+
Running
71+
-------
72+
73+
There is currently only one playbook:
74+
75+
* `matplotlib.org.yml`, for the main matplotlib.org hosting. This playbook
76+
operates on droplets with the `website` tag in DigitalOcean.

ansible.cfg

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[defaults]
2+
3+
inventory = {{CWD}}/inventories
4+
5+
interpreter_python = auto
6+
7+
# plays will gather facts by default, which contain information about
8+
# the remote system.
9+
#
10+
# smart - gather by default, but don't regather if already gathered
11+
# implicit - gather by default, turn off with gather_facts: False
12+
# explicit - do not gather by default, must say gather_facts: True
13+
gathering = smart
14+
15+
# if set to a persistent type (not 'memory', for example 'redis') fact values
16+
# from previous runs in Ansible will be stored. This may be useful when
17+
# wanting to use, for example, IP information from one group of servers
18+
# without having to talk to them in the same playbook run to get their
19+
# current IP information.
20+
fact_caching = jsonfile
21+
# This option tells Ansible where to cache facts. The value is plugin dependent.
22+
# For the jsonfile plugin, it should be a path to a local directory.
23+
# For the redis plugin, the value is a host:port:database triplet: fact_caching_connection = localhost:6379:0
24+
fact_caching_connection = /tmp
25+
26+
# Enabling pipelining reduces the number of SSH operations required to
27+
# execute a module on the remote server. This can result in a significant
28+
# performance improvement when enabled, however when using "sudo:" you must
29+
# first disable 'requiretty' in /etc/sudoers
30+
#
31+
# By default, this option is disabled to preserve compatibility with
32+
# sudoers configurations that have requiretty (the default on many distros).
33+
#
34+
pipelining = True

caddy/Caddyfile

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
# Set this variable in the environment when running in production.
1616
{$SITE_ADDRESS::2015} {
17+
# Set the variable in the environment to the Caddy directive for tls
18+
# support. By default, this is empty so you can test it locally, but
19+
# the Ansible config sets it up with the right certificate paths.
20+
{$TLS_CONFIG:}
21+
1722
root * {$SITE_DIR:.}
1823

1924
# Setup a webhook

caddy/caddy.service.override

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[Service]
2+
Environment="SITE_DIR=/usr/share/caddy"
3+
Environment="SITE_ADDRESS=https://do.matplotlib.org, https://matplotlib.org"
4+
Environment="TLS_CONFIG=tls /etc/caddy/tls/cert.pem /etc/caddy/tls/privkey.pem"

collections/requirements.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
collections:
3+
- name: ansible.posix
4+
- name: community.general
5+
- name: community.digitalocean

files/fail2ban/jail.local

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[DEFAULT]
2+
3+
# "bantime" is the number of seconds that a host is banned.
4+
bantime = 1d
5+
6+
# A host is banned if it has generated "maxretry" during the last "findtime"
7+
findtime = 1h
8+
9+
# "maxretry" is the number of failures before a host get banned.
10+
maxretry = 5

0 commit comments

Comments
 (0)