用Ansible发布Spring Boot

假如需要通过用户名密码连接服务器,mac下需要安装sshpass(https://sourceforge.net/projects/sshpass/),brew是不能直接安装的,网上也有一些资料提供通过brew安装的方法,但是本人没有成功过,直接在官方网站下载,通过源码安装集合。

下面的ansible脚本实现了Spring Boot服务的关闭,jar或者war包上传,服务的启动。

Ansible脚本

---
- hosts: 
  vars:
    project: 
    project_dir: 
    project_type: 
    project_version: 
    deploy_dir: 
  tasks:
    - name: get pid
      shell: ps -ef | grep -v grep | grep {{project}} | awk '{print $2}'
      register: running_processes
    - name: kill running processes
      shell: kill {{item}}
      with_items: "{{running_processes.stdout_lines}}"
    - wait_for:
        path: "/proc/{{item}}/status"
        state: absent
        timeout: 60
      with_items: "{{ running_processes.stdout_lines }}"
      ignore_errors: yes
      register: killed_processes
    - name: force kill stuck processes
      shell: "kill -9 {{ item }}"
      with_items: "{{ killed_processes.results | select('failed') | map(attribute='item') | list }}"
    - name: upload
      copy:
        src: "{{project_dir}}/{{project}}/target/{{project}}-{{project_version}}.{{project_type}}"
        dest: "{{deploy_dir}}/"
    - name: start
      shell: "cd {{deploy_dir}} && nohup java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED  --add-opens java.base/java.math=ALL-UNNAMED -jar {{project}}-{{project_version}}.{{project_type}} --spring.profiles.active=test >/dev/null 2>&1 &"

你可能感兴趣的:(用Ansible发布Spring Boot)