-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbook.yaml
69 lines (61 loc) · 2.13 KB
/
playbook.yaml
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
- name: Build and deploy azure2openai
hosts: web_servers
vars:
binary_name: "azure2openai"
systemd_name: "azure2openai"
project_dir: "{{ playbook_dir }}"
build_dir: "{{ project_dir }}/build/linux_x86"
deploy_dir: "/usr/local/bin"
tasks:
- name: Build the binary
ansible.builtin.command:
cmd: "make buildLinuxX86"
chdir: "{{ project_dir }}"
delegate_to: localhost
register: build_result
changed_when: build_result.rc == 0
failed_when: build_result.rc != 0
run_once: true
- name: Check if the binary exists locally
ansible.builtin.stat:
path: "{{ build_dir }}/{{ binary_name }}"
delegate_to: localhost
register: binary_stat
failed_when: not binary_stat.stat.exists
run_once: true
- name: Check remote files
ansible.builtin.stat:
path: "{{ item.path }}"
loop:
- { path: "{{ deploy_dir }}/{{ binary_name }}", register: remote_binary_stat }
- { path: "/etc/systemd/system/{{ systemd_name }}.service", register: remote_systemd_stat }
register: remote_stats
- name: Copy binary to deploy directory
become: true
ansible.builtin.copy:
src: "{{ build_dir }}/{{ binary_name }}"
dest: "{{ deploy_dir }}/{{ binary_name }}"
mode: '0755'
when: not remote_stats.results[0].stat.exists or remote_stats.results[0].stat.checksum != binary_stat.stat.checksum
notify: Restart service
- name: Ensure systemd service file exists
become: true
ansible.builtin.template:
src: "{{ project_dir }}/templates/azure2openai.service.j2"
dest: "/etc/systemd/system/{{ systemd_name }}.service"
mode: '0644'
when: not remote_stats.results[1].stat.exists
notify: Restart service
- name: Ensure service is enabled and started
become: true
ansible.builtin.systemd:
name: "{{ systemd_name }}"
state: started
enabled: yes
daemon_reload: yes
handlers:
- name: Restart service
become: true
ansible.builtin.systemd:
name: "{{ systemd_name }}"
state: restarted