1.安装
yum -y install ansible
2.创建公钥
ssh-keygen -t rsa
3.生成以后
ssh-copy-id root@192.168.10.128
ssh-copy-id root@192.168.10.153
链接
ssh root@192.168.10.153
ssh root@192.168.10.128
4.
vim /etc/ansible/hosts
[webservers]
192.168.10.128
192.168.10.153
5.继续ping
ansible webservers -m ping
(绿色就是成功)
ansible webservers -m command -a ‘yum -y install httpd’
ansible webservers -m command -a ‘service httpd start’
ansible webservers -m command -a ‘service iptables stop’
可以输入ip了
6.
ansible webservers -m shell -a 'echo “我真帅” > /var/www/html/index.html
ansible webservers -m yum -a ‘name=httpd state=lastet’
7.卸载
ansible webservers -m yum -a ‘name=httpd state=absent’
8.启动
ansible webservers -m service -a ‘name=httpd state=started enabled=yes’
vim nginx.yml
-
hosts: webservers
tasks:- name: “推从nginx包”
unarchive: src=nginx-1.12.0.tar.gz dest=/root - name: “安装配置环境”
yum: name=gcc,gcc-c++,zlib-devel,pcre-devel,openssl-devel state=installed - name: “安装nginx”
shell: cd nginx-1.12.0 && ./configure --prefix=/usr/local/nginx && make && make install - name: “启动nginx”
shell: ss -nltp | grep -wq 80 || /usr/local/nginx/sbin/nginx
tags: start-nginx
ansible-playbook nginx.yml
- name: “推从nginx包”