无聊的IT

导航

1-2 ansible 密码和秘钥登录

 

#查看配置的主机

(jiankong_venv) [yy1s@rbtnode1 ansible]$ pwd
/home/yy1s/django/extra_app/ansible
(jiankong_venv) [yy1s@rbtnode1 ansible]$ view hosts

[test_group1]
144.131.252.142 ansible_ssh_user=yy1s ansible_ssh_pass='yy1s'
144.131.252.252 ansible_ssh_user=yy1s ansible_ssh_pass='yy1s'
[test_group2]
144.131.252.162 ansible_ssh_user=root ansible_ssh_pass='root'


#查看所有主机
(jiankong_venv) [yy1s@rbtnode1 ansible]$ ansible all --list-hosts hosts (3): 144.131.252.142 144.131.252.252 144.131.252.162


#查看分组test_group1 下的主机

(jiankong_venv) [yy1s@rbtnode1 ansible]$ ansible test_group1 --list-hosts
hosts (2):
144.131.252.142
144.131.252.252

 

#ansible密码登录 首先需要安装sshpass yum -y install sshpass

(jiankong_venv) [yy1s@rbtnode1 ansible]$ ansible all -a 'ls /tmp'    #显示远程目录

 

# ansible秘钥登录

[yy1s@rbtnode1 ansible]$ ssh-keygen

[yy1s@rbtnode1 ansible]$ ssh-copy-id 144.131.252.142 #秘钥copy到144.131.252.142 服务器上

 

[yy1s@rbtnode1 ansible]$ view hosts 

[test_group1]
#144.131.252.142 ansible_ssh_user=yy1s ansible_ssh_pass='yy1s'
144.131.252.142 ansible_ssh_user=yy1s ansible_ssh_key_file='/home/yy1s/.ssh/id_rsa'  #配置秘钥登录方式1

 

[yy1s@rbtnode1 ansible]$ view cfg/ansible.cfg

private_key_file = /home/yy1s/.ssh/id_rsa     #配置秘钥登录方式2

 

[yy1s@rbtnode1 ansible]$ view hosts 

[test_group1]
144.131.252.142 ansible_ssh_user=yy1s       #此处就使用秘钥进行了登录

 

 

posted on 2019-02-12 13:55  秦寒  阅读(627)  评论(0)    收藏  举报