ansible 命令行的方式添加免密

一.环境

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 test@10.59.9.2   能直接登录就可以了

或者 ansible 10.59.9.2 -a who

等各种验证方法

略。

 

 

 

转载于:https://my.oschina.net/tacg/blog/754046

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值