diff options
Diffstat (limited to 'tasks/deploy.yml')
-rw-r--r-- | tasks/deploy.yml | 75 |
1 files changed, 20 insertions, 55 deletions
diff --git a/tasks/deploy.yml b/tasks/deploy.yml index d5e5a45..4d4ecaa 100644 --- a/tasks/deploy.yml +++ b/tasks/deploy.yml | |||
@@ -24,80 +24,45 @@ | |||
24 | CONFIGURATION_FILE: "{{ clever_login_file }}" | 24 | CONFIGURATION_FILE: "{{ clever_login_file }}" |
25 | changed_when: false | 25 | changed_when: false |
26 | 26 | ||
27 | #TODO: Improve ssh-key validation | ||
28 | - name: Accept Clever-Cloud servers | ||
29 | shell: "ssh-keyscan -H push-par-clevercloud-customers.services.clever-cloud.com >> ~/.ssh/known_hosts" | ||
30 | tags: | ||
31 | - skip_ansible_lint | ||
32 | |||
33 | - name: Deploy to Clever-Cloud | 27 | - name: Deploy to Clever-Cloud |
34 | command: "git push --force git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/{{ clever_app }}.git HEAD:refs/heads/master" | 28 | shell: "clever deploy --force" |
35 | args: | ||
36 | chdir: "{{ clever_app_root }}" | ||
37 | register: clever_deploy | ||
38 | ignore_errors: true | ||
39 | tags: | ||
40 | - skip_ansible_lint | ||
41 | |||
42 | ################################################################## | ||
43 | # Re-deploy only if its the first clever deploy for that project # | ||
44 | ################################################################## | ||
45 | |||
46 | - name: First time push to Clever-Cloud needs a full git clone | ||
47 | command: "git fetch --unshallow" | ||
48 | args: | ||
49 | chdir: "{{ clever_app_root }}" | ||
50 | when: | ||
51 | - clever_deploy is failed | ||
52 | - clever_deploy.stderr is defined | ||
53 | - clever_deploy.stderr is search("Failed to read git object") | ||
54 | tags: | ||
55 | - skip_ansible_lint | ||
56 | |||
57 | - name: Deploy to Clever-Cloud | ||
58 | command: "git push --force git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/{{ clever_app }}.git HEAD:refs/heads/master" | ||
59 | args: | ||
60 | chdir: "{{ clever_app_root }}" | ||
61 | when: | ||
62 | - clever_deploy is failed | ||
63 | - clever_deploy.stderr is defined | ||
64 | - clever_deploy.stderr is search("Failed to read git object") | ||
65 | register: clever_deploy | ||
66 | tags: | ||
67 | - skip_ansible_lint | ||
68 | |||
69 | ############################################################################## | ||
70 | # Poll deployment status from 'clever activity' command. # | ||
71 | # 'clever deploy' command is not yet 100% reliable to get a blocking command # | ||
72 | # until the deployment is over. Hence the need for a custom waiting script. # | ||
73 | ############################################################################## | ||
74 | |||
75 | - name: Watch deployment status | ||
76 | command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-wait-deploy.sh" | ||
77 | args: | 29 | args: |
78 | chdir: "{{ clever_app_root }}" | 30 | chdir: "{{ clever_app_root }}" |
79 | environment: | 31 | environment: |
80 | CONFIGURATION_FILE: "{{ clever_login_file }}" | 32 | CONFIGURATION_FILE: "{{ clever_login_file }}" |
81 | async: 2400 # 40 minutes | 33 | async: 2400 # 40 minutes |
82 | poll: 0 | 34 | poll: 0 |
83 | register: long_command | 35 | ignore_errors: true |
84 | changed_when: False | 36 | register: clever_deploy |
37 | tags: | ||
38 | - skip_ansible_lint | ||
85 | 39 | ||
86 | - name: Wait 40 minutes for deployment completion | 40 | - name: Wait up to 40 minutes for deployment completion |
87 | async_status: | 41 | async_status: |
88 | jid: "{{ long_command.ansible_job_id }}" | 42 | jid: "{{ clever_deploy.ansible_job_id }}" |
89 | register: job_result | 43 | register: job_result |
90 | until: job_result.finished | 44 | until: job_result.finished |
91 | ignore_errors: true | 45 | ignore_errors: true |
92 | delay: 30 | 46 | delay: 30 |
93 | retries: 80 # 40 minutes (80 * 30 secs delay) | 47 | retries: 80 # 40 minutes (80 * 30 secs delay) |
94 | 48 | ||
95 | - name: Waiting script logs (stdout) | 49 | ################################################################## |
50 | # Re-deploy only if its the first clever deploy for that project # | ||
51 | ################################################################## | ||
52 | |||
53 | - name: Retry deploy to clever-cloud | ||
54 | include_tasks: redeploy.yml | ||
55 | when: | ||
56 | - not job_result.rc == 0 | ||
57 | - job_result.stderr is defined | ||
58 | - job_result.stderr is search("Failed to read git object") | ||
59 | |||
60 | - name: Deploy logs (stdout) | ||
96 | debug: | 61 | debug: |
97 | var: job_result.stdout_lines | 62 | var: job_result.stdout_lines |
98 | when: job_result.stdout_lines is defined | 63 | when: job_result.stdout_lines is defined |
99 | 64 | ||
100 | - name: Waiting script logs (stderr) | 65 | - name: Deploy error logs (stderr) |
101 | debug: | 66 | debug: |
102 | var: job_result.stderr_lines | 67 | var: job_result.stderr_lines |
103 | when: job_result.stderr_lines is defined | 68 | when: job_result.stderr_lines is defined |