-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathpet_clinic.yml
More file actions
144 lines (126 loc) · 4.54 KB
/
pet_clinic.yml
File metadata and controls
144 lines (126 loc) · 4.54 KB
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
---
- name: Pet Clinic application install
hosts: "{{ rhel_inventory_group | default(omit) }}"
strategy: free
gather_facts: true
become: false
pre_tasks:
- name: Populate service facts
ansible.builtin.service_facts:
tasks:
- name: Stat /var/lib/mysql
ansible.builtin.stat:
path: /var/lib/mysql
register: datadir
- name: Configure /data/lib/mysql directory
block:
- name: Substitute file contexts configured
community.general.sefcontext:
target: /data/lib/mysql
substitute: /var/lib/mysql
state: present
become: true
- name: Data directory created
ansible.builtin.file:
state: directory
path: /data/lib/mysql
owner: 27
group: 27
mode: '0755'
become: true
- name: Symlink created
ansible.builtin.file:
state: link
src: /data/lib/mysql
dest: /var/lib/mysql
become: true
- name: SELinux file context applied
ansible.builtin.command: restorecon -Rv /var/lib/mysql /data/lib/mysql
become: true
when: not datadir.stat.exists
- name: Set selinuxuser_tcp_server flag on and keep it persistent across reboots
ansible.posix.seboolean:
name: selinuxuser_tcp_server
state: true
persistent: true
become: true
when:
- ansible_os_family == 'RedHat'
- ansible_distribution_major_version|int >= 8
- name: Adoptium yum repo enabled
ansible.builtin.yum_repository:
name: adoptium
description: Adoptium repo for Temurin OpenJDK
gpgkey: https://packages.adoptium.net/artifactory/api/gpg/key/public
baseurl: "https://packages.adoptium.net/artifactory/rpm/rhel/{{ ansible_facts.distribution_major_version }}/x86_64"
become: true
- name: Middleware installed
ansible.builtin.yum:
name:
- at
- mariadb
- mariadb-server
- temurin-17-jdk
state: present
become: true
- name: Gather package facts
ansible.builtin.package_facts:
- name: Port 8080/tcp enabled with firewalld
ansible.posix.firewalld:
port: 8080/tcp
state: enabled
permanent: true
immediate: true
become: true
when:
- ansible_os_family == 'RedHat'
- ansible_distribution_major_version|int >= 7
- ansible_facts.services['firewalld.service'] is defined and ansible_facts.services['firewalld.service'].state == 'running'
- ansible_facts.services['firewalld.service'] is defined and ansible_facts.services['firewalld.service'].status == 'enabled'
- name: Job spooling tools service started
ansible.builtin.service:
name: atd
enabled: true
state: started
become: true
- name: MariaDB database service started
ansible.builtin.service:
name: mariadb
enabled: true
state: started
become: true
- name: Database created
ansible.builtin.shell: |
mysql --user root --protocol TCP <<EOF
CREATE DATABASE IF NOT EXISTS petclinic;
ALTER DATABASE petclinic DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON petclinic.* TO 'petclinic'@'localhost' IDENTIFIED BY 'petclinic';
FLUSH PRIVILEGES;
EOF
- name: Clone spring-petclinic git repo
ansible.builtin.git:
repo: https://github.com/spring-projects/spring-petclinic.git
dest: "{{ ansible_facts.env.HOME }}/spring-petclinic"
- name: Start app web service
ansible.builtin.shell: |
echo 'cd $HOME/spring-petclinic && ./mvnw spring-boot:run -Dspring-boot.run.profiles=mysql >> $HOME/app.log 2>&1' | at now
- name: Wait for app service to start
ansible.builtin.wait_for:
port: 8080
- name: Start on boot cron entry
ansible.builtin.cron:
name: Pet Clinic app start on boot
special_time: reboot
job: 'cd $HOME/spring-petclinic && ./mvnw spring-boot:run -Dspring-boot.run.profiles=mysql >> $HOME/app.log 2>&1'
- name: Determine web app external URL
ansible.builtin.uri:
url: http://ifconfig.me/ip
return_content: true
register: external_ip
- name: Declare success
ansible.builtin.debug:
msg:
- The Spring Pet Clinic web app is installed and started successfully.
- Access the app at http://{{ external_ip.content }}:8080
- Have a nice day!
...