|
1 | | -### Lobste.rs Ansible Playbook |
| 1 | +# Lobste.rs Ansible Playbook |
2 | 2 |
|
3 | 3 | Ansible playbook for lobste.rs. |
4 | | - |
5 | 4 | Lobsters is a technology-focused link aggregation site. |
6 | 5 |
|
| 6 | +See the notes below if you're using this to set up your own site. |
| 7 | + |
7 | 8 | To run: |
8 | 9 |
|
9 | 10 | $ ansible-playbook -K prod.yml |
10 | 11 |
|
11 | | -When working on test: |
12 | | - |
13 | | - $ ansible-playbook --inventory=inventories/test.ini -K prod.yml |
14 | | - |
| 12 | +When working on staging: |
15 | 13 |
|
16 | | -#### Playbooks |
| 14 | + $ ansible-playbook --inventory=inventories/staging.ini -K staging.yml |
17 | 15 |
|
18 | | - backup - TODO: backup site. |
19 | | - prod - deploy to production. |
20 | | - restore - TODO: restore from backup. |
21 | 16 |
|
22 | | - |
23 | | -#### Inventory |
| 17 | +## Inventory |
24 | 18 |
|
25 | 19 | The following host groups are available: |
26 | 20 |
|
27 | | - backup - backup, archive, and log server. |
28 | | - console - serial console access. Used to start, stop, and debug |
29 | | - a host. |
30 | | - db - SQL server. |
31 | | - dns - authoritative DNS. |
32 | | - mx* - incoming email. |
33 | | - search - search middleware (Elasticsearch). |
34 | | - smtp* - outgoing email. |
35 | | - www* - http over SSL. |
| 21 | + db - SQL server |
| 22 | + dns - authoritative DNS |
| 23 | + mx* - incoming email |
| 24 | + smtp* - outgoing email |
| 25 | + www* - http over SSL |
36 | 26 |
|
37 | 27 | groups marked with an asterisk (*) use public SSL certificates. |
38 | 28 |
|
39 | | - |
40 | 29 | The following variables are available: |
41 | 30 |
|
42 | | - backup_server - database dump, log, static file, and email backup. |
43 | | - console_server - serial console (for grub), installer (with live cd), |
44 | | - reverse DNS, and SSH key management. |
45 | | - db_server - SQL server. |
46 | | - dns_server - authoritative DNS server. |
47 | | - mx_server - incoming mail server. |
48 | | - search_server - search middleware. |
49 | | - smtp_server - outgoing mail server. |
50 | | - www_server - http. |
| 31 | + db_server - SQL server |
| 32 | + dns_server - authoritative DNS server |
| 33 | + mx_server - incoming mail server |
| 34 | + smtp_server - outgoing mail server |
| 35 | + www_server - http/s |
51 | 36 |
|
52 | | -When a host group has more than one hostname, the _server variable |
53 | | -contains the authoritative name for the hosted sevice. |
54 | | - |
55 | | -This playbook tries not to distinguish between host variables and |
56 | | -group variables. |
| 37 | +When a host group has more than one hostname, the _server variable contains the authoritative name for the hosted sevice. |
| 38 | +This playbook tries not to distinguish between host variables and group variables. |
57 | 39 |
|
58 | 40 | https://docs.ansible.com/ansible/latest/intro_inventory.html |
59 | 41 |
|
60 | 42 |
|
61 | | -#### Tags |
62 | | - |
63 | | -The following tags can be used to limit tasks in a playbook: |
64 | | - |
65 | | - pkg - install operating system packages (deb or rpm). |
66 | | - user - create or revoke system administrator accounts |
67 | | - and public SSH keys. |
68 | | - |
69 | | -A role name can be used as a tag. When given, the tasks in that role |
70 | | -will be run. |
71 | | - |
72 | | -https://docs.ansible.com/ansible/latest/playbooks_tags.html |
73 | | - |
74 | | - |
75 | | -Roles |
76 | | ------ |
| 43 | +## Roles |
77 | 44 |
|
78 | 45 | mariadb - SQL database. |
79 | 46 | lobsters - web application. |
80 | 47 | nginx - http proxy and SSL termination. |
81 | 48 | sysadm - accounts and ssh shell acess for system administrators. |
82 | 49 | postfix - MX and smtp server. |
83 | | - puma - App server |
| 50 | + lobsters-puma - App server |
84 | 51 |
|
85 | 52 | https://docs.ansible.com/ansible/latest/playbooks.html |
86 | 53 | https://docs.ansible.com/ansible/latest/playbooks_reuse_roles.html |
87 | 54 |
|
88 | 55 |
|
89 | | -#### SSH Keys |
90 | | - |
91 | | -To use this playbook, you'll need an account in the sysadm role |
92 | | -along with an SSH key pair. |
93 | | - |
| 56 | +## SSH Keys |
| 57 | + |
| 58 | +To use this playbook, you'll need an account in the sysadm role along with an SSH key pair. |
| 59 | + |
| 60 | + |
| 61 | +## Setup Notes |
| 62 | + |
| 63 | +This is a rough checklist for turning a new Ubuntu LTS VPS into a running instance of Lobsters. |
| 64 | +If you're familiar with Linux sysadmin and Rails it should be pretty self-explanatory. |
| 65 | +You can drop by `#lobsters` on Freenode if you have questions. |
| 66 | + |
| 67 | + |
| 68 | +``` |
| 69 | + ssh root@now box |
| 70 | + set -o vi |
| 71 | + apt-get update |
| 72 | + apt-get upgrade |
| 73 | + reboot # will almost certainly be a new kernel |
| 74 | + apt-get install certbot vim fd-find tree net-tools |
| 75 | + append to /root/.bashrc |
| 76 | + alias fd=fdfind |
| 77 | + alias vi=vim |
| 78 | + set -o vi |
| 79 | + adduser pushcx |
| 80 | + cd ~pushcx |
| 81 | + cp -a /root/.ssh . |
| 82 | + chown -R pushcx:pushcx .ssh |
| 83 | + addgroup pushcx admin |
| 84 | + addgroup pushcx sudo |
| 85 | + mkdir /tmp/ansible |
| 86 | + chmod 777 /tmp/ansible |
| 87 | + time ansible-playbook -K prod.yml # should get an error about connecting to database |
| 88 | + vi ~lobsters/.bashrc, append 'export RAILS_ENV=production' |
| 89 | + mkdir -p /srv/lobste.rs/http/tmp/pids /srv/lobste.rs/http/tmp/cache |
| 90 | + chown -R lobsters:lobsters /srv/lobste.rs/http/tmp |
| 91 | + mysql -u root |
| 92 | + create database lobsters; |
| 93 | + select sha1(concat('mash keyboard', rand())); |
| 94 | + create user lobsters@'localhost' identified by "[hash]"; # may need to be @'%' for any host, an ip, etc |
| 95 | + grant all privileges on lobsters.* to 'lobsters'@'localhost'; # match host from prev |
| 96 | + create /srv/lobste.rs/http/config/database.yml |
| 97 | + create /srv/lobste.rs/http/config/initializers/production.rb |
| 98 | + create /srv/lobste.rs/http/config/secrets.yml |
| 99 | + bundle exec rails credentials:edit to create secret key base |
| 100 | + chown -R lobsters:lobsters /srv/lobste.rs/http/config |
| 101 | + echo "your@email.com" > /root/.forward |
| 102 | + run ansible again to deploy code + build assets |
| 103 | + reboot again # to see everything comes up properly automatically |
| 104 | +``` |
0 commit comments