一.环境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
等各类验证方法
略。