-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauter-checkmate.yml
97 lines (87 loc) · 3.32 KB
/
auter-checkmate.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
---
- hosts: all
become: True
# vars_prompt:
# name: "mysql_password"
# prompt: "Enter root password to be configured for mysql"
# private: yes
tasks:
- name: Install mariadb, apache and php RHEL7/CentOS7
yum:
name: "{{ item }}"
update_cache: yes
state: present
with_items:
- mariadb-server
- mariadb
- httpd
- php
- php-mysql
- php-pdo
when: (ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS') and ansible_distribution_major_version == '7'
- name: Install mysql,apache and php RHEL6/CentOS6
yum:
name: "{{ item }}"
update_cache: yes
state: present
with_items:
- mysql-server
- mysql
- httpd
- php
- php-mysql
- php-pdo
when: (ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS') and ansible_distribution_major_version == '6'
- name: Enabel and start mariadb and apache RHEL7/CentOS7
systemd:
name: "{{ item }}"
state: restarted
enabled: yes
with_items:
- httpd
- mariadb
when: (ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS') and ansible_distribution_major_version == '7'
- name: Enabel and start mysql RHEL6/CentOS6
service:
name: "{{ item }}"
state: restarted
enabled: yes
with_items:
- httpd
- mysqld
when: (ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS') and ansible_distribution_major_version == '6'
- name: Check if mysql_secure_installation has already been run
stat:
path: /root/.mysql_secure_installation_run
register: mysql_secure_installation_run
- name: prompt for mysql root password
pause:
prompt: "Enter root password to be configured for mysql"
#private: yes
register: mysql_password
when: mysql_secure_installation_run.stat.exists == False
- name: Run equivalent commands to mysql_secure_installation
shell: "{{ item }}"
with_items:
- mysql -e "UPDATE mysql.user SET Password=PASSWORD('{{ mysql_password.user_input }}') WHERE User='root';"
- mysql -e "DELETE FROM mysql.user WHERE User='';"
- mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
- mysql -e "DROP DATABASE IF EXISTS test;"
- mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';"
- mysql -e "FLUSH PRIVILEGES;"
- touch /root/.mysql_secure_installation_run
when: mysql_secure_installation_run.stat.exists == False
- name: Create /root/.my.cnf
shell: echo -e "[client]\nuser=root\npassword={{ mysql_password.user_input }}" > /root/.my.cnf
when: mysql_secure_installation_run.stat.exists == False
- name: check if the auter-checkmate database already exists
shell: mysql -e "show databases like 'auter%'"
register: databaseExists
- name: Copy the auter-checkmate database creation sql file to the server
copy:
src: ./auter-checkmate.sql
dest: /root/auter-checkmate.sql
when: databaseExists.stdout == ""
- name: Create the database structure
shell: mysql -sf < /root/auter-checkmate.sql
when: databaseExists.stdout == ""