-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbook.yml
109 lines (91 loc) · 3.05 KB
/
playbook.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
- hosts: localhost
tasks:
- name: Install Fedora packages
dnf: name={{ item }}
with_items:
- git-core
- make
- gcc
- python-devel
- python-pip
- python-psycopg2
- openssl-devel
- libselinux-python
- name: Install postgresql
dnf: name={{ item }}
with_items:
- postgresql96
- postgresql96-devel
- postgresql96-contrib
- postgresql96-server
- name: Initiate database
command: service postgresql initdb
creates=/var/lib/pgsql/9.6/data/postgresql.conf
- name: Start PostgreSQL and enable at boot
service: name=postgresql
enabled=yes
state=started
- name: Ensure PostgreSQL is listening on all localhost
lineinfile: dest=/var/lib/pgsql/9.6/data/postgresql.conf
regexp='^#?listen_addresses\s*='
line="listen_addresses = '127.0.0.1'"
state=present
notify: restart postgresql
- lineinfile: dest=/var/lib/pgsql/9.6/data/pg_hba.conf
regexp='host\s+all\s+all\s+127.0.0.1/32\s+md5'
line='host all all 127.0.0.1/32 md5'
insertbefore=BOF
notify: restart postgresql
- name: Give the vagrant user permission to database
postgresql_user: name=vagrant role_attr_flags=SUPERUSER
become: yes
become_user: postgres
- name: Upgrade virtualenv to latest version
shell: '[ -x /usr/local/bin/virtualenv ] || pip install -U virtualenv'
- name: Install app dependencies in a virtualenv
pip:
requirements=/vagrant/requirements.txt
virtualenv=/home/vagrant
become: yes
become_user: vagrant
- name: Make "vagrant" shell auto-activate the virtual environment
lineinfile:
dest=/home/vagrant/.bashrc
line='source $HOME/bin/activate'
- name: Create pycon-prod database role to avoid errors during prod import
become: yes
become_user: postgres
postgresql_user: db=template1 name=pycon-prod
- name: Create application database "pycon"
become: yes
become_user: postgres
register: database_creation
postgresql_db: name=pycon
encoding=UTF8
lc_collate=en_US.UTF-8
lc_ctype=en_US.UTF-8
template=template0
- name: Migrate the application database if we just created it
become: yes
become_user: vagrant
when: database_creation | changed
shell: /home/vagrant/bin/python manage.py migrate
chdir=/vagrant
- name: Copy db backup script and make it executable
become: yes
become_user: vagrant
command: cp db_backup.sh /home/vagrant/db_backup.sh
chmod +x /home/vagrant/db_backup.sh
- name: Add cron for db backup
become: yes
become_user: vagrant
cron: minute="0"
hour="5,2"
job="/home/vagrant/db_backup.sh"
- name: Make bash history more sane
lineinfile:
dest: /home/vagrant/.bashrc
line: 'HISTCONTROL=erasedups; unset HISTFILE'
handlers:
- name: restart postgresql
service: name=postgresql state=restarted