-
Notifications
You must be signed in to change notification settings - Fork 272
/
Copy pathapp.yml
executable file
·84 lines (74 loc) · 2.6 KB
/
app.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
#!/usr/bin/env ansible-playbook
---
#==============================================================#
# File : app.yml
# Desc : copy and launch docker compose app
# Ctime : 2025-01-11
# Mtime : 2025-01-11
# Path : app.yml
# Docs : https://pigsty.io/docs/app
# License : AGPLv3 @ https://pigsty.io/docs/about/license
# Copyright : 2018-2025 Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#
- name: NODE ID
become: yes
hosts: all
gather_facts: no
roles:
- { role: node_id ,tags: id }
#- { role: docker ,tags: docker }
# Run docker compose application (require the docker module)
- name: APP INSTALL
hosts: all
gather_facts: no
become: yes
vars:
#app: pgadmin # any entries in the app/ folder, required
#app_config: {} # .env entries to override
#app_dir: [] # additional directories to be created (ansible file module)
tasks:
# check app defined and dir exists
- name: check app arg defined
tags: [always, app_preflight]
become: no
fail: msg="the 'app' arg is required, use -e app=<appname> to specify the name in the app/ folder"
when: app is not defined
# abort if local app not exists
- name: check app folder exists
tags: app_check
connection: local
become: no
block:
- name: check local app folder
stat: path={{ playbook_dir }}/app/{{ app }}
register: app_folder_stat
- name: abort if local app not exists
fail: {msg: "app/{{ app }} folder not exist"}
when: not app_folder_stat.stat.exists
# create app dir
- name: setup app dir
tags: app_dir
when: app_dir is defined and app_dir | length > 0
file: "{{ item }}"
with_items: "{{ app_dir }}"
# copy docker app folder to /opt/<app>
- name: copy app resource dir
tags: app_install
copy: src="{{ playbook_dir }}/app/{{ app }}/" dest="/opt/{{ app }}/"
# append entries to app .env config (override existing entries)
- name: overwrite docker app .env
tags: app_config
when: app_config is defined
lineinfile:
path: /opt/{{ app }}/.env
regexp: '^{{ item.key | upper }}='
line: '{{ item.key | upper }}={{ item.value if item.value is not boolean else item.value | string | lower }}'
create: yes
loop: "{{ app_config | dict2items }}"
# it may take a while to pull images, or very fast if you already have local image loaded
- name: launch app
tags: app_launch
shell:
cmd: make
chdir: /opt/{{ app }}
...