ansible角色-批量部署编译tomcat
配置公钥私钥和ansible的hosts清单
将所有要的安装包放进指定目录
[root@localhosts ~]# ansible-galaxy init tomcat
[root@localhosts ~]# cd tomcat/
[root@localhosts tomcat]# cp /usr/local/jdk-8u211-linux-x64.tar.gz /root/tomcat/files/
[root@localhosts tomcat]# cp /data/app/apache-tomcat-8.5.47.tar.gz /root/tomcat/files/
定义剧本调用roles文件
[root@localhosts ~]# vim tomcat.yml
- hosts: all
remote_user: root
roles:
- tomcat
编辑剧本
[root@localhosts ~]# vim tomcat/tasks/main.yml
#Tomcat task file written by HYF
- name: mkdir_/data/app/
file: path=/data/app/ state=directory
- name: copy jdk_package
unarchive: scr=jdk-8u211-linux-x64.tar.gz dest=/usr/local/ copy=yes
- name: copy tomcat_package
unarchive: scr=apache-tomcat-8.5.47.tar.gz dest=/data/app/ copy=yes
- name: mv_java
shell: mv /usr/local/jdk1.8.0_211 /usr/local/java
- name: mv tomcat
shell: mv /data/app/apache-tomcat-8.5.47 /data/app/tomcat
- name: variable_1
lineinfile: path=/etc/profile line="export JAVA_HOME=/usr/local/java \nexport TOMCAT_HOME=/usr/local/tomcat \nexport JRE_HOME=/usr/local/java/jre \nexport PATH=$TOMCAT_HOME/bin:$JAVA_HOME/bin:$JRE_HOME/bin:$PATH"
- name: copy_startup.sh
copy: src=/usr/local/tomcat/bin/startup.sh dest=/data/app/tomcat/bin/
- name: start_tomcat
shell: nohup /data/app/tomcat/bin/startup.sh &
编辑ansible服务器/data/app/tomcat/bin/startup.sh这个启动脚本
在脚本第二行添加一个source /etc/profile命令
直接执行剧本