ansible tomcat自動部署項目

1.實現的功能:git

   從nexus下載war包,自動部署到tomcat上,而且從gitlab上拉取配置文件,替換到項目中web

2 ansible的目錄結構:spring

 

3 ansible主要文件的內容shell

  3.1deploy.yml:tomcat

   - hosts: testhost1
     user: root
     gather_facts: true
     roles:
      - deployapp

 3.2main.yml:
- name: stop tomcat service
  shell: ps -ef | grep {{ tomcat_home }} | grep -v grep | awk '{print $2}'  | sed -e "s/^/kill -9 /g" | sh -webapp

- name: "delete {{ project }}.war.bak file"
  file: path={{ tomcat_home }}/webapps/{{ project }}.war.bak state=absentgitlab

- name: back old war
  shell: mv '{{ tomcat_home }}/webapps/{{ project }}.war' '{{ tomcat_home }}/webapps/{{ project }}.war.bak' removes='{{ tomcat_home }}/webapps/{{ project }}.war'url

- name: replace config file
  template: src={{ item }} dest={{ config_path }} owner=root group=root
  with_items:
   - "{{ project }}.properties"
   - "logback.xml"debug

- name: download {{ project }}.war
  get_url: url='{{ pkg_url }}' dest={{ tomcat_home }}/webapps/ owner=root group=root

- name: start tomcat service
  shell: chdir='{{ tomcat_home }}/bin' nohup ./startup.sh -Dspring.profiles.active=server $
  register: tomcat_status

- debug: var=tomcat_status.stdout_lines

3.3dev:

[testhost1]
10.10.10.1

[testhost1:vars]
config_path=/opt/config/my_ci_demo
tomcat_home=/usr/local/tomcat
project=my_ci_demo
pkg_url=http://10.10.10.1:8081/nexus/content/repositories/snapshots/my_ci_demo.war

4.啓動任務

  ansible-playbook -i inventory/dev ./deploy.yml

相關文章
相關標籤/搜索