main.yml:
--- - include: install_tomcat7.yml tags: tomcat7 - include: install_tomcat8.yml tags: tomcat8
install_tomcat7.yml:
--- - name: "复制文件到远程主机" copy: src={{ item.src }} dest={{ item.dest }} with_items: - src: jdk-7u79-linux-x64.rpm dest: /usr/local/src/ - src: java17.sh dest: /etc/profile.d/ - name: "安装jdk" yum: name: /usr/local/src/jdk-7u79-linux-x64.rpm state: present - name: "重新加载环境变量" shell: "source /etc/profile.d/java17.sh" - name: "复制tomcat文件到远程服务器并解压" unarchive: src=apache-tomcat-7.0.64.zip dest=/data/ copy=yes owner=staplesapp group=admin - name: "对解压后的文件重命名" shell: mv /data/apache-tomcat-7.0.64 /data/tomcat7 - name: "对tomcat进行相关配置" shell: find /data/tomcat7/bin -name "*.sh" | xargs chmod +x - name: "启动tomcat" shell: 'nohup /data/tomcat7/bin/startup.sh &'
install_tomcat8.yml:
--- - name: "复制文件到远程主机" copy: src={{ item.src }} dest={{ item.dest }} with_items: - src: jdk-8u111-linux-x64.rpm 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.d/java18.sh" - name: "安装tomcat" unarchive: src=apache-tomcat-8.0.30.tar.gz dest=/data/ copy=yes owner=staplesapp group=admin - name: "对解压后的文件重命名" shell: mv /data/apache-tomcat-8.0.30 /data/tomcat8 - name: "启动tomcat" shell: 'nohup /data/tomcat8/bin/startup.sh &'
安装tomcat7:ansible-playbook tomcat.yml --tags tomcat7
安装tomcat8:ansible-playbook tomcat.yml --tags tomcat8
ansible-playbook之include结合tags的使用
原文地址:http://blog.51cto.com/liuzhengwei521/2094348