ubuntu上安装ansible

1 在最新的ubuntu系统上安装ansible : sudo ape-get install ansible

2 切换到root用户 生成ssh免密登陆

  ssh-keygen -t rsa

  ssh-copy-id -i /root/.ssh/id_rsa.pub root@ip(ip是被ansible管理的节点地址)

  

root@pxy-p:/etc/ansible# ssh-keygen -t rsa
Generating public/private rsa key pair.
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:
SHA256:AsNJM46Bt5GCyQtaNXQOik+hKDAD9hRQZkIuMz3I/1g root@pxy-p
The key's randomart image is:
+---[RSA 2048]----+
|XB=XX .          |
|%O@O O           |
|%*B+* .          |
|+*o. o           |
|  .. E. S        |
|    +  .         |
|   . .           |
|                 |
|                 |
+----[SHA256]-----+
root@pxy-p:/etc/ansible# ssh-copy-id -i /root/.ssh/id_rsa.pub root@100.98.40.134
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@100.98.40.134's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@100.98.40.134'"
and check to make sure that only the key(s) you wanted were added.

root@pxy-p:/etc/ansible# ssh 100.98.40.134
Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.15.0-29-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

6 个可升级软件包。
0 个安全更新。

Last login: Tue Oct 30 16:29:25 2018 from 100.98.40.167
root@pxy-snow:~# exit
注销
Connection to 100.98.40.134 closed.
root@pxy-p:/etc/ansible# 

如果ssh 免秘钥登陆节点失败:

  

解决方法:

1) 以root身份,chmod +w /etc/ssh/sshd_config

2) vi /etc/ssh/sshd_config

3) 将PermitRootLogin no改成PermitRootLogin yes

4) service sshd restart