Ansible安装配置与简单使用(2)

6)远程ssh互信配置以及测试
#复制公钥到client
[ansible@node1 .ssh]$ scp authorized_keys ansible@192.168.253.129:
The authenticity of host '192.168.253.129 (192.168.253.129)' can't be established.
RSA key fingerprint is fa:73:59:f5:08:95:b2:2e:7f:3e:52:91:8a:e6:47:1f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.253.129' (RSA) to the list of known hosts.
ansible@192.168.253.129's password: 
authorized_keys                                                            100%  998    1.0KB/s  00:00   
[ansible@node1 .ssh]$ scp authorized_keys ansible@192.168.253.130:
The authenticity of host '192.168.253.130 (192.168.253.130)' can't be established.
RSA key fingerprint is fa:73:59:f5:08:95:b2:2e:7f:3e:52:91:8a:e6:47:1f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.253.130' (RSA) to the list of known hosts.
ansible@192.168.253.130's password: 
authorized_keys                                                            100%  998    1.0KB/s  00:00   
[ansible@node1 .ssh]$ scp authorized_keys ansible@192.168.253.131:
The authenticity of host '192.168.253.131 (192.168.253.131)' can't be established.
RSA key fingerprint is fa:73:59:f5:08:95:b2:2e:7f:3e:52:91:8a:e6:47:1f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.253.131' (RSA) to the list of known hosts.
ansible@192.168.253.131's password: 
authorized_keys                                                            100%  998    1.0KB/s  00:00 
 
#测试是否互信成功 
[ansible@node1 .ssh]$ ssh 192.168.253.129
[ansible@node2 ~]$ mkdir .ssh
[ansible@node2 ~]$ mv authorized_keys .ssh/
[ansible@node2 ~]$ chmod -R 700 .ssh/
 
[ansible@node1 .ssh]$ ssh 192.168.253.130
[ansible@node3 ~]$ mkdir .ssh
[ansible@node3 ~]$ mv authorized_keys .ssh/
[ansible@node3 ~]$ chmod -R 700 .ssh/
 
[ansible@node1 .ssh]$ ssh 192.168.253.131
[ansible@node3 ~]$ mkdir .ssh
[ansible@node3 ~]$ mv authorized_keys .ssh/
[ansible@node3 ~]$ chmod -R 700 .ssh/
 
[ansible@node1 .ssh]$ ssh 192.168.253.129
[ansible@node2 ~]$ exit
logout
Connection to 192.168.253.129 closed.
[ansible@node1 .ssh]$ ssh 192.168.253.130
[ansible@node3 ~]$ exir
-bash: exir: command not found
[ansible@node3 ~]$ exit
logout
Connection to 192.168.253.130 closed.
[ansible@node1 .ssh]$ ssh 192.168.253.131
[ansible@node4 ~]$ exit
logout
Connection to 192.168.253.131 closed.

——使用ansible
1)使用ping模块测试是否成功
[ansible@node1 ~]$ chmod g-wx,o-wx .python-eggs/
[ansible@node1 ~]$ ansible all -m ping
192.168.253.131 | success >> {
    "changed": false, 
    "ping": "pong"
}
 
192.168.253.129 | success >> {
    "changed": false, 
    "ping": "pong"
}
 
192.168.253.130 | success >> {
    "changed": false, 
    "ping": "pong"
}
 
127.0.0.1 | success >> {
    "changed": false, 
    "ping": "pong"
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/c591231b6a0a3df736946eb5e73babf5.html