项目实战:通过ansible上线 批量部署Jdk+Tomcat

在这里插入图片描述

[root@ansible ansible]# cat jenkins.yml
- hosts: ansible-web1
  user: root
  vars_files:
  - /etc/ansible/vars/file.yml
  tasks:
##配置JDK,上传jdk、tomcat的安装包到/usr/src
  - name: configure JDK1.8
    copy: src={{ src_jdk_path }}  dest={{ dest_jdk_path }}
  - name: unzip JDK
    shell: tar -xvzf /usr/src/jdk-8u211-linux-x64.tar.gz -C /usr/local
  - name: rename to java
    shell: mv /usr/local/jdk1.8.0_211 /usr/local/java
  - name: configure JDK envirement1
    shell: echo "JAVA_HOME=/usr/local/java" >> /etc/profile
  - name: configure JDK envirement2
    shell: echo 'PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile
##Tomcat
  - name: copy tomcat
    copy: src={{ src_tomcat_path }} dest={{ dest_tomcat_path }}
  - name: unzip tomcat
    shell: tar -xvzf /usr/src/apache-tomcat-8.5.45.tar.gz -C /usr/local
  - name: rename to tomcat
    shell: mv /usr/local/apache-tomcat-8.5.45 /usr/local/tomcat
  - name: copy startup file
    copy: src=/usr/src/startup.sh dest=/usr/local/tomcat/bin
##Jenkins
  - name: copy jenkins
    copy: src=/usr/src/jenkins.war  dest=/usr/local/tomcat/webapps/
    notify: start jenkins
  handlers:
  - name: start jenkins
    shell: nohup /usr/local/tomcat/bin/startup.sh &

或者直接修改被控节点的启动文件

- hosts: webserver
  user: root
  tasks:
  - name: copy file
    copy: src=/usr/src/jdk-8u211-linux-x64.tar.gz  dest=/usr/src
  - name: unzip
    shell: tar -xzf /usr/src/jdk-8u211-linux-x64.tar.gz -C /usr/local
  - name: as file
    shell: mv /usr/local/jdk1.8.0_211  /usr/local/java
  - name: configure env1
    shell: echo "JAVA_HOME=/usr/local/java" >> /etc/profile
  - name: configure env2
    shell: echo 'PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH' >> /etc/profile
  - name: copy tomcat
    copy: src=/usr/src/apache-tomcat-8.5.45.tar.gz  dest=/usr/src
  - name: unzip tomcat
    shell: tar -xzf /usr/src/apache-tomcat-8.5.45.tar.gz -C /usr/local/
  - name: mv tomcat
    shell: mv /usr/local/apache-tomcat-8.5.45  /usr/local/tomcat
  - name: sed tomcat
    shell: sed -ri '1a source /etc/profile' /usr/local/tomcat/bin/startup.sh
    notify: start tomcat
  handlers:
  - name: start tomcat
    shell: nohup /usr/local/tomcat/bin/startup.sh &

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值