-
Notifications
You must be signed in to change notification settings - Fork 2
/
5_create_db_user.yml
79 lines (69 loc) · 2.54 KB
/
5_create_db_user.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
- name: Create DB user for monitoring with appdynamics
hosts: database
become: yes
become_user: root
vars:
appd_dbuser_username: "{{ secret_dbuser_username }}"
appd_dbuser_password: "{{ secret_dbuser_password }}"
appd_db_agent: "{{ hostvars['db_agent']['ansible_host'] }}"
tasks:
# create localhost DB user
- name: "Copy SQL commands to /root"
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: '0644'
vars:
user: "{{ appd_dbuser_username }}"
host: 'localhost'
password: "{{ appd_dbuser_password }}"
with_items:
- { src: ./cross_role_data/mysql_check_user.sql.j2, dest: /root/mysql_check_user.sql }
- { src: ./cross_role_data/mysql_create_monitor_user.sql.j2, dest: /root/mysql_create_monitor_user.sql}
- name: "Check for DB user {{ appd_dbuser_username }}@localhost"
shell:
cmd: mysql -N -s < mysql_check_user.sql;
register: local_user_count
- name: "Create DB user {{ appd_dbuser_username }}@localhost"
shell:
cmd: mysql -N -s < mysql_create_monitor_user.sql;
when: local_user_count['stdout'] == "0"
- name: "Delete files"
file:
path: "{{ item.dest }}"
state: absent
with_items:
- { dest: /root/mysql_check_user.sql }
- { dest: /root/mysql_create_monitor_user.sql }
# create DB-Agent DB user
- name: "Copy SQL commands to /root"
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: '0644'
vars:
user: "{{ appd_dbuser_username }}"
host: "{{ appd_db_agent }}"
password: "{{ appd_dbuser_password }}"
with_items:
- { src: ./cross_role_data/mysql_check_user.sql.j2, dest: /root/mysql_check_user.sql }
- { src: ./cross_role_data/mysql_create_monitor_user.sql.j2, dest: /root/mysql_create_monitor_user.sql}
- name: "Check for DB user {{ appd_dbuser_username }}@{{ appd_db_agent }}"
shell:
cmd: mysql -N -s < mysql_check_user.sql;
register: local_user_count
- name: "Create DB user {{ appd_dbuser_username }}@{{ appd_db_agent }}"
shell:
cmd: mysql -N -s < mysql_create_monitor_user.sql;
when: local_user_count['stdout'] == "0"
- name: "Delete files"
file:
path: "{{ item.dest }}"
state: absent
with_items:
- { dest: /root/mysql_check_user.sql }
- { dest: /root/mysql_create_monitor_user.sql }