ansible-playbook之include结合tags的使用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansible-playbook之include结合tags的使用相关的知识,希望对你有一定的参考价值。
此playbook的作用:通过指定标签(tags),来说明是安装tomcat7还是tomcat8main.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的使用的主要内容,如果未能解决你的问题,请参考以下文章