ansible 命令行的方式添加免密

一.環境ssh

1.1 操做系統ide

[root@host-xxxsoft]# lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.6 (Final)
Release:        6.6
Codename:       Final
[root@host-xxx soft]# 操作系統

1.2 ansbile 版本.net

[test@host playbooks]$ ansible --version
ansible 2.1.1.0
  config file = /wls/test/playbooks/ansible.cfg
  configured module search path = Default w/o overrides
[test@host playbooks]$ ip

二 添加免密get

2.1 hosts 文件io

[testroot]
10.59.9.2
10.59.9.3class

[testroot:vars]
ansible_ssh_user="root"
ansible_ssh_pass="root"test

2.2 執行命令登錄

ansible testroot -m authorized_key -a "user=test key='{{ lookup('file', '/wls/test/.ssh/id_rsa.pub') }}' path=/wls/test/.ssh/authorized_keys manage_dir=no"

2.3 說明

我是用root用戶登陸到各主機,而後給各主機的test 用戶添加免密

 

2.4 爲何用root 用戶,由於用其餘用戶會報權限不足,須要修改目錄權限。

 

三.驗證

驗證方法:ssh test@10.59.9.2   能直接登陸就能夠了

或者 ansible 10.59.9.2 -a who

等各類驗證方法

略。

相關文章
相關標籤/搜索