一.环境 1.1 操作系统 [root@host-xxxsoft]# lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core
一.环境
1.1 操作系统
[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 版本
[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]$
二 添加免密
2.1 hosts 文件
[testroot]
10.59.9.2
10.59.9.3
[testroot:vars]
ansible_ssh_user="root"
ansible_ssh_pass="root"
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 [email protected] 能直接登录就可以了
或者 ansible 10.59.9.2 -a who
等各种验证方法
略。