forked from watchdogpolska/feder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvagrant_provision_ansible.yaml
121 lines (109 loc) · 2.92 KB
/
vagrant_provision_ansible.yaml
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
110
111
112
113
114
115
116
117
118
119
120
121
---
- hosts: all
vars:
db_name: feder
db_user: feder
db_pass: feder
db_names:
- "{{ db_name }}"
- "test-{{ db_name }}"
env_path: "~/env"
src_path: "/vagrant"
requirements_path: "{{src_path}}/requirements/local.txt"
settings: {
DJANGO_SETTINGS_MODULE: "config.settings.local",
DATABASE_URL: "mysql://{{db_user}}:{{db_pass}}@localhost/{{db_name}}"
}
tasks:
- name: Add repository key to the system
apt_key: keyserver=keyserver.ubuntu.com id=0xF1656F24C74CD1D8
register: repository_status
become: yes
- name: Install MariaDB repository
apt_repository:
repo: 'deb [arch=amd64,i386,ppc64el] http://mariadb.kisiek.net/repo/10.1/ubuntu xenial main'
state: present
become: yes
- name: Update repository info
# Workaround of https://github.com/ansible/ansible/issues/21006
apt:
update_cache: yes
when: repository_status.changed
become: yes
- name: Install OS-level libraries and application
apt:
name: "{{item}}"
state: latest
with_items:
- python2.7
- build-essential
- mariadb-server
- git
- python-pip
- libmariadbclient18
- libmariadbclient-dev
- virtualenv
- python-dev
- libffi-dev
- libssl-dev
- libjpeg-dev
- libpng12-dev
- libxml2-dev
- libxslt1-dev
- libjpeg62
become: yes
- name: Install OS-level Python dependencies
pip: name={{item}} state=latest
with_items:
- pip
- wheel
- mysqlclient # Required for Ansible mysql_db and mysql_user module
become: yes
- name: Create a new MariaDB database
mysql_db:
name: "{{ item }}"
encoding: utf8
state: "present"
become: yes
items: "{{ db_names }}"
- name: Create a new MariaDB user
mysql_user:
name: "{{ db_user }}"
password: "{{ db_pass }}"
host: "localhost"
priv: '*.*:ALL'
state: present
become: yes
- name: Flush privileges
command: mysql -e "FLUSH PRIVILEGES;"
become: yes
- name: Create virtualenv
pip:
requirements: "{{ requirements_path }}"
virtualenv: "{{ env_path }}"
- name: Create virtualenv
pip:
name: "django"
virtualenv: "{{ env_path }}"
- name: Update activator
lineinfile:
dest: "{{ env_path }}/bin/activate"
state: present
regexp: '^export {{ item.key }}='
line: 'export {{ item.key }}="{{ item.value }}"'
with_dict: "{{ settings }}"
- name: Update ~/.bashrc to autostart in project
lineinfile:
dest: "~/.bashrc"
state: present
regexp: '^{{item}}$'
line: '{{item}}'
with_items:
- "source {{ env_path }}/bin/activate;"
- "cd {{src_path }};"
- name: execute database migrations
django_manage:
command: migrate
app_path: "{{ src_path }}"
virtualenv: "{{ env_path}}"
environment: "{{ settings }}"