--- - hosts: "{{ deploy_host }}" gather_facts: no vars: src: "/srv/ansible/fqz/cache" tmp: "/tmp/all_deploy" url: "https://deploy1:vkJXnWZ8KKyy2T0@gz-gitlab.vipthink.cn" src_config_file: "{{ src }}/configfiles/{{ env }}-{{ pj }}.env.json" dest_path: "/data/wwwroot/{{ domain }}{{ deploy_path }}" rollback_path: "/data/wwwroot/rollback/{{ domain }}-{{ tag }}/{{ deploy_path }}" tasks: - name: "shop ems mkt clear" shell: "rm -rf {{ src }}/{{ pj }}-{{ env }}" run_once: true connection: local when: pj in ['shop','ems','mkt'] - name: "pull {{ git }} {{ tag }}" git: repo: "{{ url }}{{ git }}" dest: "{{ src }}/{{ pj }}-{{ env }}" version: "{{ tag }}" run_once: true connection: local - name: "mkt,ems,shop composer" shell: "composer install" args: chdir: "{{ src }}/{{ pj }}-{{ env }}" run_once: true connection: local when: pj in ['shop','ems','mkt'] - name: "store create 777 directory" shell: "mkdir public/uploads runtime || true;chmod 777 runtime/ public/uploads/" args: chdir: "{{ src }}/{{ pj }}-{{ env }}" run_once: true connection: local when: pj == "store" - name: "get configfile from apollo" shell: "curl -s https://{{ env }}-apollo-cs.vipthink.cn/configfiles/json/{{ pj }}/default/application --connect-timeout 2 > {{ src_config_file }};rm -f {{ src }}/{{ pj }}-{{ env }}/vipthink.env.json || true" run_once: true connection: local - name: "check configfile and left to project root path" shell: "[ `cat {{ src_config_file }}|wc -l` -gt 2 ] && cp -f {{ src_config_file }} {{ src }}/{{ pj }}-{{ env }}/vipthink.env.json || true" run_once: true connection: local - name: "remote host create directory" file: path: "{{ dest_path }}" state: directory owner: www group: www - name: "remote host create rollback directory" file: path: "{{ rollback_path }}" state: directory owner: www group: www when: env == "prod" - name: publish code synchronize: src: "{{ src }}/{{ pj }}-{{ env }}/" dest: "{{ dest_path }}/" partial: yes compress: yes rsync_timeout: 0 rsync_opts: ['--chown=www:www','--chmod=ugo=rwX','--exclude-from=/srv/ansible/fqz/rsync_exclude_files'] perms: no use_ssh_args: no set_remote_user: no delete: "{% if pj in ['fz','auth','cs','vns','shop-admin','shop-h5'] %} yes {% else %} no {% endif %}" - name: publish code to rollback path synchronize: src: "{{ src }}/{{ pj }}-{{ env }}/" dest: "{{ rollback_path }}/" partial: yes compress: yes rsync_timeout: 0 rsync_opts: ['--chown=www:www','--chmod=ugo=rwX','--exclude-from=/srv/ansible/fqz/rsync_exclude_files'] perms: no use_ssh_args: no set_remote_user: no when: env == "prod" - name: housekeep last 7 rollback release shell: "ls -t|grep {{ domain }}-|awk 'NR>7'|xargs rm -rf" args: chdir: "{{ rollback_path }}" ignore_errors: yes - name: "auth,cs,vns project execute ./build.sh" shell: composer install;php dof compile;chmod -R 0777 var args: chdir: "{{ dest_path }}" ignore_errors: yes when: pj in ['auth','cs','vns'] - name: "fz restart" shell: "rm -f runtime/swoft.pid runtime/swoft.command;pkill -9 -f swoft" args: chdir: "{{ dest_path }}" ignore_errors: yes when: pj == "fz" - name: "store chmod 777 /var/lib/php/session" shell: "chmod 777 /var/lib/php/session" when: pj == "store"