ansible安装tomcat一个很low的写法,后面再更新高级的写法

注:下面with_items显示不正常,具体请看图片~

---
- hosts: all
  remote_user: root
  tasks:
  - name: "复制jdk文件到目标服务器"
    copy:
      src: ./{{ item.src }}
      dest: "{{ item.dest }}"
    with_items:
      - src: jdk-8u111-linux-x64.rpm
        dest: /usr/local/src/
      - src: apache-tomcat-8.0.30.tar.gz
        dest: /usr/local/src/
      - src: java18.sh
        dest: /etc/profile.d/
  - name: "安装jdk"
    yum:
      name: /usr/local/src/jdk-8u111-linux-x64.rpm
      state: present
  - name: "配置java环境变量"
    shell: "source /etc/profile"
  - name: "安装tomcat"
    unarchive:
      src: /usr/local/src/apache-tomcat-8.0.30.tar.gz
      dest: /usr/local/
      copy: no
  - name: "为tomcat创建软链接"
    file:
      src: /usr/local/apache-tomcat-8.0.30
      dest: /usr/local/tomcat
      state: link
  - name: "给sh脚本增加执行权限"
    shell: 'find /usr/local/tomcat/bin/ -name "*.sh" | xargs chmod +x'
  - name: "启动tomcat"
    shell: 'nohup /usr/local/tomcat/bin/startup.sh &'

ansible-playbook安装tomcat1.8_第1张图片

以上playbook经过测试是没有问题的,后面学习后会给上传更严谨的写法~