-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordpress.yml
137 lines (118 loc) · 4.15 KB
/
wordpress.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
---
- hosts: all
vars:
domain: example.org
mysql_user_database: example
mysql_password: nXhvHYgbAKdEsyzfLZU4ObPqyv64Awxz4JWzC6Z3pbwZ1tbR1n5ktRzLNNJKs6b2
mysql_root_password: E9AihdfcDuzayG5DWVHPJ8yPnD3JANS4i4XifemPUkvjB1dGtg3R4qWHHH4ILfEc
title: Lorem Ipsum
wordpress_user: admin
wordpress_password: TxLIRcwdA32EAOu9npxg0ZDhl9lFb2aGe7oOh4LaJGdoE8K7MarBYVZr45ELL2Cj
wordpress_email: [email protected]
tasks:
- name: request letsencrypt rsa certificate
command: certbot certonly --cert-name {{ domain }} --key-type rsa --rsa-key-size 4096 --keep-until-expiring -d {{ domain }} -d www.{{ domain }}
- name: request letsencrypt ecdsa certificate
command: certbot certonly --cert-name {{ domain }}-ecdsa --key-type ecdsa --elliptic-curve secp384r1 --keep-until-expiring -d {{ domain }} -d www.{{ domain }}
- name: create base directories for domains
file:
path: /var/www/{{ domain }}
state: directory
owner: www-data
group: www-data
- name: configure domain site
template:
src: etc/nginx/sites-available/domain.j2
dest: /etc/nginx/sites-available/{{ domain }}
- name: enable domain site
file:
src: /etc/nginx/sites-available/{{ domain }}
dest: /etc/nginx/sites-enabled/{{ domain }}
state: link
- name: reload nginx
service:
name: nginx
state: reloaded
- name: cronjob
cron:
name: "{{ domain }}"
minute: "*/5"
job: "/usr/bin/php -f /var/www/{{ domain }}/wp-cron.php"
user: www-data
- name: set mysql root password
mysql_user:
name: root
password: "{{ mysql_root_password }}"
- name: set mysql root password in /root/.my.cnf
register: mysql_conf_root
copy:
content: "[client]\nuser=root\npassword={{ mysql_root_password }}"
dest: /root/.my.cnf
mode: "0600"
- name: restart mysql
when: mysql_conf_root.changed
service:
name: mysql
state: restarted
- name: create mysql database
mysql_db:
name: "{{ mysql_user_database }}"
state: present
- name: create mysql user
mysql_user:
name: "{{ mysql_user_database }}"
password: "{{ mysql_password }}"
priv: "{{ mysql_user_database }}.*:ALL,GRANT"
state: present
- name: download WordPress
unarchive:
src: https://wordpress.org/latest.tar.gz
dest: /var/www/{{ domain }}
remote_src: yes
owner: www-data
group: www-data
extra_opts:
- --xform
- s/wordpress//
- name: check if WordPress is installed
stat:
path=/var/www/{{ domain }}/wp-config.php
register: installed
- name: setup wp-config
when: installed.stat.exists == False
command: mv /var/www/{{ domain }}/wp-config-sample.php /var/www/{{ domain }}/wp-config.php
- name: get salts for wp-config
when: installed.stat.exists == False
uri:
url: "https://api.wordpress.org/secret-key/1.1/salt/"
return_content: True
method: GET
register: salt
- name: configure wp-config
when: installed.stat.exists == False
copy:
dest: /var/www/{{ domain }}/wp-config.php
content: |
<?php
define('DB_NAME', '{{ mysql_user_database }}' );
define('DB_USER', '{{ mysql_user_database }}' );
define('DB_PASSWORD', '{{ mysql_password }}' );
define('DB_HOST', 'localhost' );
{{ salt.content }}
define('WP_DEBUG', false );
define('DISABLE_WP_CRON', true);
$table_prefix = 'wp_';
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
require_once ABSPATH . 'wp-settings.php';
- name: install wp-cli
get_url:
url: https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
dest: /usr/local/bin/wp
mode: 0755
- name: install database tables
become: true
become_user: www-data
command: wp core install --path=/var/www/{{ domain }} --url="https://{{ domain }}" --title="{{ title }}" --admin_user="{{ wordpress_user }}" --admin_password="{{ wordpress_password }}" --admin_email="{{ wordpress_email }}"
when: installed.stat.exists == False