ansible-playbook之include結合tags的使用
阿新 • • 發佈:2018-04-03
ansible-playbook的tag此playbook的作用:通過指定標簽(tags),來說明是安裝tomcat7還是tomcat8
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的使用