什么是ansible?
ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架.
怎么使用?
这里以2个server(ip1,ip2)上说明
step1:install ansible of each server
yum install -u ansible
step2:change hosts of each server
vim /etc/ansible/hosts
[web_group]
ip1
ip2
step3:add ssh not need passwd to login of each server
ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub ip1
ssh-copy-id -i /root/.ssh/id_rsa.pub ip2
step4:verify
ansible all -a ''who"
step5:add yml file
vim test.yml
---
- hosts:web_group
remote_user:root
tasks:
- name:install docker
com: yum install -y install docker
tags: conf
notify
- server restart
- name: server start
service: name=docker state=started enabled=true
handlers:
- name:server restart
service: name=docker state=restarted
step6 :run ansible
ansible-playbook install_docker.yuml
其他比较好的文章
http://ju.outofmemory.cn/entry/67581
http://docs.ansible.com/ansible/latest/index.html
遗留问题
yml 文件的格式
ssh-keygen -t rsa:命令的作用将本机的公钥复制到远程机器的authorized_keys文件中么?
我把ip1的/root/.ssh下的id_pub.rsa放到ip2 /root/.ssh下的authorized_keys
service sshd restart ,
但是ssh ip2:任然需要使用passwd,why?