#This is the default ansible ‘hosts‘ file.
#It should live in /etc/ansible/hosts
#- Comments begin with the ‘#‘ character
#- Blank lines are ignored
#- Groups of hosts are delimited by [header] elements
#- You can enter hostnames or ip addresses
#- A hostname/ip can be a member of multiple groups
#Ex 1: Ungrouped hosts, specify before any group headers.
##green.example.com
##blue.example.com
##192.168.100.1
##192.168.100.10
#Ex 2: A collection of hosts belonging to the ‘webservers‘ group
#[webservers]
##alpha.example.org
##beta.example.org
##192.168.1.100
##192.168.1.110
[webserver] //添加
192.168.252.173 //添加
[mysql] //添加
192.168.252.174 //添加
2)生成密钥对并将公钥推送给被管理端
ssh-keygen -t rsa //以rsa的类型生成密钥对
enerating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): //回车
Created directory ‘/root/.ssh‘.
Enter passphrase (empty for no passphrase): //输入密码
Enter same passphrase again: //再次输入
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:udpIx9U0dKSLCND1RFwGy3PK/ZdczW1fep2AoaO3GGQ root@ansible
The key‘s randomart image is:
+---[RSA 2048]----+
| .. ..o+o+.o |
| .. +.+ o |
| . =.= |
| . +.Ooo .o|
| ESo=.+. B|
| o..o. .ooB|
| .o+. o+=|
| . =+ . o |
| o... |
+----[SHA256]-----+
cd ~
cd .ssh
ssh-copy-id root@192.168.252.173
ssh-copy-id root@192.168.252.174 //将公钥推送给被管理端
ssh-agent bash //免交互
ssh-add
至此ansible安装以及主机清单配置完成。(注:如果连接失败请检查ansibleserver和被管理端是否能ping通,如能ping通,可以删除.ssh下的密钥,重新生成并下发)
原文:http://blog.51cto.com/13842738/2311723