-
Notifications
You must be signed in to change notification settings - Fork 12
/
sync.yml
103 lines (89 loc) · 3.68 KB
/
sync.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
- name: set paths for syncing deployment to target host
hosts: deploy
connection: local
tasks:
- include: tasks/set-paths.yml
tags: always
- include_vars:
dir: env_vars
files_matching: site_all_env_(all|{{ deployment_environment }}).yml$
tags: always
- include_vars:
dir: env_secrets
files_matching: site_all_env_(all|{{ deployment_environment }}).yml$
tags: always
- block:
- name: list files in deployment to check permissions
find:
paths:
- "{{ root_path }}"
- "{{ ngi_containers }}"
- "{{ igenomes_dir }}"
recurse: yes
excludes: "{{ exclude_pattern }}"
file_type: any
register: find
- name: test if all files have correct permissions
pause:
prompt: Some files are not {{ item }}, continue anyway? Hit return to continue or Ctrl+C and 'A' to abort!
when: find.files | rejectattr(item) | list |length > 0
with_items:
- rgrp
- wgrp
- roth
register: cont_p
- name: test if all files have correct group ownership
pause:
prompt: Some files are not owned by {{ item }}, continue anyway? Hit return to continue or Ctrl+C and 'A' to abort!
when: find.files | rejectattr('gr_name', '==', item) | list |length > 0
with_items:
- "{{ ngi_sw_group }}"
register: cont_g
- name: log a warning that permissions are wrong
debug:
msg: "!! WARNING !! Sync was initiated although some files had wrong permissions or ownership"
when: item.results | rejectattr('skipped', 'defined') | list | length > 0 or item.results | selectattr('skipped', 'defined') | rejectattr('skipped') | list | length > 0
with_items:
- "{{ cont_p }}"
- "{{ cont_g }}"
tags: permission_check
- name: sync deployment to target host
hosts: target
connection: ssh
tags: transfer
tasks:
- name: set the rsync log file path
set_fact:
rsync_log_file: "{{ hostvars['deploy']['deployment_target'] }}/{{ hostvars['deploy']['deployment_version'] }}.rsync.log"
- name: sync the deployment to the target host
synchronize:
src: "{{ item }}"
dest: "{{ deployment_remote_path }}"
archive: yes
compress: yes
use_ssh_args: yes
ssh_connection_multiplexing: yes
rsync_timeout: 60
rsync_opts:
- --omit-dir-times
- --relative
- --progress
- --verbose
- --no-owner
- "--log-file={{ rsync_log_file }}"
- "{{ exclude_pattern | map('regex_replace', '^(.*)$', '--exclude=\"\\1\"') | join(' ') }}"
- "{{ '--dry-run' if (deployment_environment == 'devel') else '' }}"
with_items:
- "{{ hostvars['deploy']['root_path'] | replace(deployment_remote_path, deployment_remote_path + '/.') }}"
- "{{ hostvars['deploy']['ngi_containers'] | replace(deployment_remote_path, deployment_remote_path + '/.') }}"
- "{{ hostvars['deploy']['igenomes_dir'] | replace(deployment_remote_path, deployment_remote_path + '/.') }}"
- name: create or move the latest symlink to {{ deployment_version }}
file:
src: "{{ hostvars['deploy']['root_path'] }}"
dest: "{{ hostvars['deploy']['root_path'] | dirname | regex_replace('^(.*)/?$', '\\1/latest') }}"
state: link
when:
- not deployment_environment == 'devel'
- not hostvars['deploy']['branch_name'] == 'bimonthly'
- debug:
msg: Done! Each site should now execute {{ hostvars['deploy']['ngi_resources'] }}/create_static_contents_[upps | sthlm].sh