Skip to content

Commit 5a3f03f

Browse files
committed
add psycopg2 to reqs.txt
1 parent 440694f commit 5a3f03f

File tree

21 files changed

+305
-0
lines changed

21 files changed

+305
-0
lines changed

deploy/group_vars/all

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
deploy_user: deployer
2+
deploy_group: deployers
3+
ssh_dir: "/home/matt/serverconfig/"
4+
ssh_key_name: "serverconfig"
5+
6+
db_name: "chapter6"
7+
db_user: "{{ deploy_user }}"
8+
db_password: pleaseuseagoodpassword

deploy/hosts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[init_config]
2+
142.93.123.128 ansible_python_interpreter=/usr/bin/python3
3+
142.93.119.59 ansible_python_interpreter=/usr/bin/python3
4+
5+
[common]
6+
142.93.123.128 ansible_python_interpreter=/usr/bin/python3
7+
142.93.119.59 ansible_python_interpreter=/usr/bin/python3
8+
9+
[webserver]
10+
142.93.123.128 ansible_python_interpreter=/usr/bin/python3
11+
12+
[database]
13+
142.93.119.59 ansible_python_interpreter=/usr/bin/python3

deploy/init_config.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
ansible-playbook -vvvv ./init_config.yml --private-key=/home/matt/do_deploy -u root -i ./hosts

deploy/roles/common/tasks/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# handles server protection and configuration regardless of server type
2+
- include: security.yml
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# install security configuration
2+
- name: ensure python packages are installed
3+
apt:
4+
name: "{{ item }}"
5+
update_cache: yes
6+
become: yes
7+
with_items:
8+
- "python3-pip"
9+
- "python3-dev"
10+
- "fail2ban"
11+
12+
13+
- name: enable SSH within the firewall
14+
ufw: rule=allow port=22
15+
become: yes
16+
17+
- name: enable firewall itself
18+
ufw: state=enabled
19+
become: yes
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# handles server protection and configuration for database servers
2+
- include: security.yml
3+
- include: postgresql.yml
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# install and configure PostgreSQL database
2+
- name: ensure postgresql database packages are installed
3+
apt: name={{ item }}
4+
with_items:
5+
- postgresql
6+
- libpq-dev
7+
- python3-psycopg2
8+
- postgresql-client
9+
- postgresql-client-common
10+
become: yes
11+
12+
13+
- name: create database instance
14+
postgresql_db: name={{ db_name }}
15+
become: yes
16+
become_user: postgres
17+
18+
19+
- name: configure separate PostgreSQL user
20+
postgresql_user: db={{ db_name }} name={{ db_user }}
21+
password={{ db_password }} priv=ALL
22+
role_attr_flags=NOSUPERUSER
23+
become: yes
24+
become_user: postgres
25+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# install security configuration
2+
- name: enable PostgreSQL access
3+
ufw: rule=allow port=5432
4+
become: yes
5+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# establish non-root user with sudo privileges
2+
- name: create a non-root group
3+
group:
4+
name: "{{ deploy_group }}"
5+
state: present
6+
7+
8+
- name: create non-root user
9+
user:
10+
name: "{{ deploy_user }}"
11+
group: "{{ deploy_group }}"
12+
shell: "/bin/bash"
13+
state: present
14+
15+
16+
- name: add authorized_key to non-root user
17+
authorized_key:
18+
user: "{{ deploy_user }}"
19+
state: present
20+
key: "{{ lookup('file', ssh_dir + ssh_key_name + '.pub') }}"
21+
22+
23+
- name: add non-root group to sudo privileges
24+
lineinfile:
25+
dest: /etc/sudoers
26+
state: present
27+
regexp: "^{{ deploy_group }}"
28+
line: "%{{ deploy_group }} ALL=(ALL) NOPASSWD: ALL"
29+
validate: visudo -cf %s
30+
31+
32+
- name: disable root SSH logins
33+
replace:
34+
destfile: /etc/ssh/sshd_config
35+
regexp: "^PermitRootLogin yes"
36+
replace: "PermitRootLogin no"
37+
backup: no
38+
39+
40+
- name: disable SSH logins by password
41+
replace:
42+
destfile: /etc/ssh/sshd_config
43+
regexp: "^PasswordAuthentication yes"
44+
replace: "PasswordAuthentication no"
45+
backup: no
46+
47+
48+
- name: restart SSH service
49+
service:
50+
name: ssh
51+
state: restarted
52+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
- name: restart nginx
3+
service: name=nginx state=restarted
4+
become: true

0 commit comments

Comments
 (0)