aboutsummaryrefslogblamecommitdiffhomepage
path: root/tasks/deploy.yml
blob: 287dd410bd30c4a8fdffb737bc5c1f7d7b1c501b (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                       
                                                                   
                                                                              

                                  
              
                                                                            


                                                 
                                                     
                                                                               

                                  
              
                                                   



                                                           

                                  

                                                 
                     
 
                              
                                



                                                 

                          



                         
 

                                                 
                                             

                            
                     

                                               
 











                                                                  

                                

                                          
                                  







                                                         
- name: Configure Drain
  when: syslog_server is defined or clever_syslog_server is defined
  command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-set-drain.sh"
  args:
    chdir: "{{ clever_app_root }}"
  environment:
    SYSLOG_UDP_SERVER: "{{ clever_syslog_server | default(syslog_server) }}"
    CONFIGURATION_FILE: "{{ clever_login_file }}"

- name: Configure Domain
  when: domain is defined or clever_domain is defined
  command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-set-domain.sh"
  args:
    chdir: "{{ clever_app_root }}"
  environment:
    DOMAIN: "{{ clever_domain | default(domain) }}"
    CONFIGURATION_FILE: "{{ clever_login_file }}"

- name: Push Environment
  shell: "clever env import < {{ clever_app_confdir }}/env"
  args:
    chdir: "{{ clever_app_root }}"
  environment:
    CONFIGURATION_FILE: "{{ clever_login_file }}"
  changed_when: false

- name: Deploy to Clever-Cloud
  shell: "clever deploy --force"
  args:
    chdir: "{{ clever_app_root }}"
  environment:
    CONFIGURATION_FILE: "{{ clever_login_file }}"
  async: 2400 # 40 minutes
  poll: 0
  ignore_errors: true
  register: clever_deploy
  tags:
    - skip_ansible_lint

- name: Wait 40 minutes for deployment completion
  async_status:
    jid: "{{ clever_deploy.ansible_job_id }}"
  register: job_result
  until: job_result.finished
  ignore_errors: true
  delay: 30
  retries: 80 # 40 minutes (80 * 30 secs delay)

##################################################################
# Re-deploy only if its the first clever deploy for that project #
##################################################################

- name: Retry deploy to clever-cloud
  include_tasks: redeploy.yml
  when:
    - not job_result.rc == 0
    - job_result.stderr is defined
    - job_result.stderr is search("Failed to read git object")

- name: Deploy logs (stdout)
  debug:
    var: job_result.stdout_lines
  when: job_result.stdout_lines is defined

- name: Deploy error logs (stderr)
  debug:
    var: job_result.stderr_lines
  when: job_result.stderr_lines is defined

- name: Fail in case of timeout or failure
  fail:
    msg: "Deployment failed. Please check logs above."
  when: not job_result.finished or not job_result.rc == 0