-
Notifications
You must be signed in to change notification settings - Fork 1
/
site.yml
146 lines (139 loc) · 4.9 KB
/
site.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
- hosts: all
become: true
vars:
mysql_root_pass: vagrant
phpmyadmin_pass: vagrant
phpmyadmin_host: mysql.lk
nvm_user: vagrant
handlers:
- name: restart nginx
service: name=nginx state=restarted enabled=yes
tasks:
- name: Update repository
apt:
update_cache: yes
- name: Update all packages to the latest version
apt:
upgrade: dist
- name: Install essential tools
apt: name={{ item }} state=present
with_items:
- git
- vim
- curl
- wget
- build-essential
- gcc
- make
# Start of PPA
# Add nginx stable repository from PPA and install its signing key.
- name: Add nginx PPA
apt_repository:
repo: 'ppa:nginx/stable'
- name: Add redis PPA
apt_repository:
repo: 'ppa:chris-lea/redis-server'
- name: Add PHP PPA
apt_repository:
repo: 'ppa:ondrej/php'
# End of PPA
# Start of Installation
- name: Install nginx
apt:
name: nginx
- name: Install redis
apt:
name: redis-server
# NOTE: the password problem
# https://coderwall.com/p/sqdaya/mysql-server-installation-with-custom-password-in-ansible--2
- name: Set MySQL root password before installing
debconf: name='mysql-server' question='mysql-server/root_password' value='{{ mysql_root_pass }}' vtype='password'
- name: Confirm MySQL root password before installing
debconf: name='mysql-server' question='mysql-server/root_password_again' value='{{ mysql_root_pass }}' vtype='password'
- name: Install MySQL
apt: name={{ item }} state=present
with_items:
- mysql-server
- mysql-client
- name: Install PHP7
apt: name={{ item }} state=present
# TODO: enable error report
with_items:
- php7.3-cli
- php7.3-fpm
- php7.3-zip
- php7.3-redis
- php7.3-xdebug
- php7.3-mbstring
- php7.3-curl
- php7.3-gd
- php7.3-intl
- php7.3-mysql
- php7.3-sqlite3
- php7.3-xml
- php7.3-mbstring
- name: Check if composer is installed
# http://stackoverflow.com/questions/21892603/how-to-make-ansible-execute-a-shell-script-if-a-package-is-not-installed
command: bash -c 'which composer'
register: composer_check
failed_when: False
- name: Install composer
become_user: root
command: bash -c 'curl -sS https://getcomposer.org/installer | php && chmod +x composer.phar && mv composer.phar /usr/local/bin/composer'
when: composer_check.stdout.find('composer') == -1
- name: Set phpmyadmin webserver
# TODO: how to skip this
debconf: name='phpmyadmin' question='phpmyadmin/reconfigure-webserver' value='apache2' vtype='multiselect'
- name: Set phpmyadmin dbconfig
debconf: name='phpmyadmin' question='phpmyadmin/dbconfig-install' value='true' vtype='boolean'
- name: Set phpmyadmin mysql admin user
debconf: name='phpmyadmin' question='phpmyadmin/mysql/admin-user' value='root' vtype='string'
- name: Set phpmyadmin mysql admin user password
debconf: name='phpmyadmin' question='phpmyadmin/mysql/admin-pass' value='{{ mysql_root_pass }}' vtype='password'
- name: Set phpmyadmin admin user password
debconf: name='phpmyadmin' question='phpmyadmin/mysql/app-pass' value='{{ phpmyadmin_pass }}' vtype='password'
- name: Set phpmyadmin admin user password confirm
debconf: name='phpmyadmin' question='phpmyadmin/app-password-confirm' value='{{ phpmyadmin_pass }}' vtype='password'
- name: Install phpmyadmin
apt:
name: phpmyadmin
- name: Update hosts for phpmyadmin
lineinfile:
dest: /etc/hosts
# NOTE: must use double quote https://github.com/ansible/ansible/issues/4818
line: "127.0.0.1\t{{ phpmyadmin_host }}"
- name: Copy nginx config for phpmyadmin
template:
src: /vagrant/templates/phpmyadmin.j2
dest: /etc/nginx/conf.d/phpmyadmin.conf
owner: root
group: root
# TODO: file mode
notify: restart nginx
- name: Install nvm for user vagrant
become_user: "{{ nvm_user }}"
git: repo=https://github.com/creationix/nvm.git dest=~/.nvm
- name: Export NVM_DIR
become_user: "{{ nvm_user }}"
lineinfile:
dest: ~/.bashrc
line: "export NVM_DIR=$HOME/.nvm"
create: yes
- name: Add nvm.sh to bashrc
become_user: "{{ nvm_user }}"
lineinfile:
dest: ~/.bashrc
line: "[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads nvm"
create: yes
- name: Check if node is installed
become_user: "{{ nvm_user }}"
command: bash -c 'which node'
register: node_check
failed_when: False
- name: Install latest node LTS
become_user: "{{ nvm_user }}"
# Thanks to https://truongtx.me/2015/11/02/ansible-install-and-work-with-nodejs-using-nvm
command: bash -c '. ~/.nvm/nvm.sh; nvm install lts/*; nvm alias default lts/*'
# FIXME: the check is not working, it still change every time run provision
when: node_check.stdout.find('node') == -1
# End of Installation