-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.yml
More file actions
57 lines (57 loc) · 2.73 KB
/
Copy pathdeploy.yml
File metadata and controls
57 lines (57 loc) · 2.73 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
---
# code: language=ansible
# yaml-language-server: $schema=https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible.json
- name: Deploy App
hosts: all
become: false
tasks:
- name: ソースコードのチェックアウト
ansible.builtin.git:
repo: "{{ app_repo }}"
dest: "{{ app_deploy_path }}"
version: "{{ app_repo_branch }}"
register: checkout_result
- name: セットアップ処理
when: checkout_result is changed
block:
# - name: rsyncを使ったデプロイ
# ## @see https://docs.ansible.com/ansible/latest/collections/ansible/posix/synchronize_module.html
# ansible.posix.synchronize:
# src: dist/
# dest: rsync://{{ inventory_hostname }}{{ app_deploy_path }}
# rsync_opts: "{{ rsync_exclude_opts | map('regex_replace', '(.+)', '--exclude=\\1') }}"
# delegate_to: 127.0.0.1
- name: 新規セットアップ処理
when: not checkout_result.before
block:
## 以下、新規設置時の処理
- name: 初期セットアップ処理
ansible.builtin.shell:
cmd: |
echo "新規設置時の処理を実装してください。"
chdir: "{{ app_deploy_path }}"
## 以下、更新時の共通処理
- name: 更新時の処理
ansible.builtin.shell:
cmd: |
echo "更新時の処理を実装してください。"
chdir: "{{ app_deploy_path }}"
- name: デプロイ完了時の通知処理
## @see https://docs.ansible.com/ansible/latest/collections/community/general/slack_module.html
community.general.slack:
token: "{{ lookup('env', 'SLACK_TOKEN') }}"
channel: "{{ lookup('env', 'SLACK_CHANNEL') | default(omit, true) }}"
username: "{{ lookup('env', 'SLACK_USERNAME') | default(omit, true) }}"
color: "#00ff00"
msg: '{{ inventory_hostname }}へのデプロイが完了しました。'
when: lookup('env', 'SLACK_TOKEN') | length > 0
rescue:
- name: デプロイ失敗時の通知処理
## @see https://docs.ansible.com/ansible/latest/collections/community/general/slack_module.html
community.general.slack:
token: "{{ lookup('env', 'SLACK_TOKEN') }}"
channel: "{{ lookup('env', 'SLACK_CHANNEL') | default(omit, true) }}"
username: "{{ lookup('env', 'SLACK_USERNAME') | default(omit, true) }}"
color: "#ff0000"
msg: '{{ inventory_hostname }}へのデプロイに失敗しました。'
when: lookup('env', 'SLACK_TOKEN') | length > 0