一、生成密钥
ssh-keygen
二、将密钥拷贝到目标主机
ssh-copy-id -i root@10.230.20.103
遇到需要输入的地方直接回车
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
--------------------
The key's randomart image is:
--------------------
三、在主机列表中添加机器信息
[root@localhost ~]# vi /etc/ansible/hosts
10.230.20.103
四、对主机发送命令
[root@localhost ~]# ansible -m command -a 'ls' '10.230.20.103'
10.230.20.103 | SUCCESS | rc=0 >>
anaconda-ks.cfg
install.log
install.log.syslog
jboss
jboss-eap-6.2
redis-3.2.0.tar
zookeeper-3.4.6.tar.gz
命令执行成功