Ansible部署完之后会发现一直无法通过自动化启动Tomcat, 这是要将环境变量添加到系统文件 /root/.bashrc 与/root/.bash_profile。
Ansible的特性:
1、首先准备3台机器
ansible机器:192.168.52.34
目标主机:192.168.52.35
目标主机:192.168.52.36
2、关闭防火墙
[root@localhost ~]# systemctl stop firewalld [root@localhost ~]# setenforce 0
3、配置免密登录
4、安装ansible
yum -y install ansible
5、在ansible的配置文件中添加目标主机
vim /etc/ansible/hosts
## [webservers] ## alpha.example.org ## beta.example.org ## 192.168.1.100 ## 192.168.1.110 [tomcat] 192.168.52.35 192.168.52.36 # If you have multiple hosts following a pattern you can specify # them like this:
## www[001:006].example.com
6、检查ansible与目标主机是否连通
7、上传tomcat、jdk
[root@localhost ~]# rz
[root@localhost ~]# rz
[root@localhost ~]# ls anaconda-ks.cfg apache-tomcat-8.5.35.tar.gz jdk-8u131-linux-x64_.rpm original-ks.cfg [root@localhost ~]#
8、编写tomcat.yml
[root@localhost ~]# vim tomcat.yml
--- - hosts: tomcat tasks: - name: 关闭防火墙 shell: systemctl stop firewalld - name: 关闭selinux shell: setenforce 0 - name: 推送jdk Java环境 copy: src=jdk-8u131-linux-x64_.rpm dest=/root - name: 创建文件夹 file: path=/opt/tomcat state=directory - name: 推送tomcat的压缩包 unarchive: src=apache-tomcat-8.5.35.tar.gz dest=/opt/tomcat - name: 安装jdk yum: name=jdk-8u131-linux-x64_.rpm state=installed - name: 启动tomcat shell: nohup /opt/tomcat/apache-tomcat-8.5.35/bin/startup.sh
9、检查tomcat.yml
[root@localhost ~]# ansible-playbook --syntax-check tomcat.yml #这个是警告的意思可以忽略 [WARNING]: Could not match supplied host pattern, ignoring: tomcat
playbook: tomcat.yml [root@localhost ~]#
10、执行tomcat.yml
[root@localhost ~]# ansible-playbook tomcat.yml
11、完成