能用,写的太差
更新点
把项目和tomcat启动程序分开
加点变量
1.cat roles/http/tasks/main.yml - name: pro file: path=/opt/apps/{{pro_dir}} state=directory - name: copy profile copy: src=/opt/src/profile dest=/etc/profile force=yes owner=root group=root mode=0644 - name: copy jdk copy: src=/opt/src/jdk.tar.gz dest=/usr/java/ - name: tar shell: chdir=/usr/java tar xvzf jdk.tar.gz - name: rm file: dest=/usr/java/jdk.tar.gz state=absent - name: copy maven copy: src=/opt/src/mvn.tar.gz dest=/usr/java/ - name: tar shell: chdir=/usr/java tar xvzf mvn.tar.gz && source /etc/profile - name: rm file: dest=/usr/java/mvn.tar.gz state=absent - name: copy tomcat copy: src=/opt/src/tomcat.tar.gz dest=/opt/install/ - name: tar shell: chdir=/opt/install tar xvzf tomcat.tar.gz && rm -rf {{tomcat_dir}} && mv tomcat {{tomcat_dir}} - name: rm file: dest=/opt/install/tomcat.tar.gz state=absent - name: copy server.xml template: src=server.xml dest=/opt/install/{{tomcat_dir}}/conf/ force=yes mode=0644 - name: rm webapps file: dest=/opt/install/{{tomcat_dir}}/webapps/ state=absent - name: copy apr copy: src=/opt/src/apr.tar.gz dest=/usr/local - name: tar shell: chdir=/usr/local tar xvzf apr.tar.gz - name: rm file: dest=/usr/local/apr.tar.gz state=absent - name: copy tomcat.sh copy: src=/opt/src/tomcat.sh dest=/opt/install/tomcat.sh - name: modify tomcat.sh shell: chdir=/opt/install sed -i ‘s%/install/tomcat%/install/{{tomcat_dir}}%g‘ tomcat.sh - name: add user action: user name=tomcat password=faJxjj/6hKXPs update_password=always shell=/bin/bash home=/opt/install - name: modify file: path=/opt/install/{{tomcat_dir}}/ owner=tomcat group=tomcat mode=0755 - name: 首次启动tomcat shell: chdir=/opt/install nohup sh tomcat.sh & - name: copy test copy: src=/etc/ansible/playbook/roles/http/meta/test dest=/opt/apps/{{pro_dir}}/ tags: - updateconf notify: - stop tomcat service - start tomcat service 2.server.xml <Context path="" docBase="/opt/apps/{{pro_dir}}/" reloadable="false" /> 3.- name: stop tomcat service shell: "ps -ef |grep /opt/install/{{tomcat_dir}} |grep -v grep |awk ‘{print $2}‘ |xargs kill -9" - name: start tomcat service shell: chdir=/opt/install nohup sh tomcat.sh & 4.执行yml ansible-playbook -i hosts site.yml --extra-vars "tomcat_dir=test pro_dir=test" tomcat_dir tomcat启动程序名字 pro_dir 项目名字 5.wget http://xx:8080/test/test.html 测试
本文出自 “人,要有自己的想法” 博客,请务必保留此出处http://szgb2014.blog.51cto.com/340201/1785552
原文地址:http://szgb2014.blog.51cto.com/340201/1785552