天下風雲出我輩
一入江湖歲月催

Ansible-Playbook部署Tomcat

Ansible-Playbook部署Tomcat案例:

---
- hosts: tomcat
tasks:

- name: 解压jdk,tomcat包到远程主机/opt目录下
  unarchive:
  src:'{{ item.src }}'
  dest:'{{ item.dest }}'
  with_items:
    - { src: '/root/jdk-8u181-linux-x64.tar.gz', dest: '/opt/' }
    - { src: '/root/apache-tomcat-8.5.32.tar.gz', dest: '/opt' }

- name: 创建jdk及tomcat目录的软连接
  file:
    src:'{{ item.src }}'
    dest:'{{ item.dest }}'
    state:link
  with_items:
    - { src: '/opt/jdk1.8.0_181', dest: '/opt/jdk' }
    - { src: '/opt/apache-tomcat-8.5.32', dest: '/opt/tomcat' }

- name: 添加全局变量
  blockinfile:
    path:/etc/profile
    block: |
      export JAVA_HOME=/opt/jdk
      export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
      export PATH=$PATH:$JAVA_HOME/bin

- name: 重新加载全局变量

  shell:source /etc/profile

- name: 添加jdk变量到tomcat脚本中
  blockinfile:
    path:/opt/tomcat/bin/setclasspath.sh
    insertafter:"^#!/bin/sh"
    block:|
      export JAVA_HOME=/opt/jdk
      export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
      export PATH=$PATH:$JAVA_HOME/bin

- name: 复制配置文件到远程主机
  copy:
  src:/opt/tomcat/conf/server.xml
  dest:/opt/tomcat/conf/server.xml
  owner:root
  group:root
  mode:0644

- name: 启动 tomcat

shell:sh /opt/tomcat/bin/startup.sh

 

赞(3) 打赏
未经允许不得转载:Anonym0x1 » Ansible-Playbook部署Tomcat

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏