【经验】ansible 批量推送公钥
1.使用 ssh-keygen -t rsa生成密钥对
ssh-keygen -t rsa
2.推送单个公钥到远程机器
格式: ssh-copy-id -i ~/.ssh/id_rsa.pub username@[ip,hostname]
ssh-copy-id -i ~/.ssh/id_rsa.pub username@192.168.100.2
3.添加ansible hosts
编辑/etc/ansible/hosts,没有则创建些文件。
格式:【主机名】 【主机地址】 【主机密码】 默认是root用户来进行的
[tomcat-servers]
1 ansible_ssh_user="tomcat" ansible_ssh_host=192.168.100.1 ansible_ssh_pass="test"
2 ansible_ssh_user="tomcat" ansible_ssh_host=192.168.100.2 ansible_ssh_pass="test"
新版的ansible(2.4) hosts有更新, 用以下方式:
[tomcat-servers]
192.168.100.1 ansible_user=tomcat ansible_ssh_pass="test"
192.168.100.2 ansible_user=tomcat ansible_ssh_pass="test"
4.批量推送公钥到远程机器
机器多的情况下,使用ssh-copy-id方法有些费时,使用ansible-playbook推送ymal,这里使用到了authoried_keys模块,可以参考 http://docs.ansible.com/authorized_key_module.html
将以下文件命名为:push.ssh.ymal
# Using alternate directory locations:
- hosts: tomcat-servers
user: tomcat
tasks:
- name: ssh-copy
authorized_key: user=tomcat key="{{ lookup('file', '/home/tomcat/.ssh/id_rsa.pub') }}"
tags:
- sshkey
5.执行推送命令
ansible-playbook push.ssh.ymal
6.如若报错,解决
Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host's fingerprint to your known_hosts file to manage this host.
修改host_key_checking(默认是check的):
vi /home/xiangdong/ansible/ansible.cfg
# uncomment this to disable SSH key host checking
host_key_checking = False
7.测试
#查看各机器时间
ansible all -a date
#ansible all -m command -a date # 作用同上 #ping
ansible all -m ping
输出结果:
$ ansible all -m ping
192.168.100.1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
参考:
1.http://mageedu.blog.51cto.com/4265610/1412028
2.http://www.justwinit.cn/post/8973/
【经验】ansible 批量推送公钥的更多相关文章
- 自动化运维工具ansible学习+使用ansible批量推送公钥到远程主机
目录: 一.ansible简介 1.1.ansible是什么 1.2.ansible如何工作 1.3.ansible优缺点 1.4.ansible安装方式 1.5.ansible文件简单介绍 1.6. ...
- ansible 批量推送公钥
这里我们使用ansible的playbook 的功能来推送秘钥 使用方法参见:http://blog.csdn.net/magedu_linux/article/details/48529645 这里 ...
- ansible 批量推送ssh秘钥
ansible 批量推送ssh秘钥 参考:http://docs.ansible.com/ansible/authorized_key_module.html # vi /etc/ansible/ho ...
- Ansible配置批量推送公钥到被管理端
01.yum安装ansible(推荐) sudo yum install ansible 02.配置被管理端主机IP清单 [root@ansible_50 ansible]$ cp /etc/ansi ...
- shell脚本批量推送公钥
目的:新建管理机,为了实现批量管理主机,设置密匙登陆 原理:.通过密钥登陆,可以不用密码 操作过程: 1.生成密匙 ssh-keygen 2.查看密匙 ls ~/.ssh/ 有私匙id_rsa公匙 ...
- 基于Codeigniter框架实现的APNS批量推送—叮咚,查水表
最近兼职公司已经众筹成功的无线门铃的消息推送出现了问题,导致有些用户接收不到推送的消息,真是吓死宝宝了,毕竟自己一手包办的后台服务,影响公司信誉是多么的尴尬,容我简单介绍一下我们的需求:公司开发的是一 ...
- SEO教程:快速增加360搜索引擎收录,360自动推送批量推送版
上次改编了一下百度的JS推送代码,实现了批量推送 传送门>>>百度链接提交-js代码推送批量推送版 这次我们来研究360js自动推送代码. <script> (funct ...
- 百度链接提交-js代码推送批量推送版
1原百度JS链接推送代码 首先我们来看一下原百度JS链接推送代码是这*样的 用百度自己的话讲:JS链接推送代码以网页为最小对象,服务于全平台多终端,PC站和移动站均可使用.安装代码的页面在任意平台(浏 ...
- ansible用authorized_key模块批量推送密钥到受控主机(免密登录)(ansible2.9.5)
一,ansible的authorized_key模块的用途 用来配置密钥实现免密登录: ansible所在的主控机生成密钥后,如何把公钥上传到受控端? 当然可以用ssh-copy-id命令逐台手动处理 ...
随机推荐
- HTML与CSS二三事
概述 HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可以让浏览器 ...
- Linux SAMBA Practical
Samba配置 on Ap1-10.*.16.81首先,判斷samba服務是否安裝?[root@ap01 ~]# rpm -qa|grep sambasamba-client-3.5.10-125.e ...
- Nodejs简单介绍以及在windows环境下安装与配置流程
简介 一. Nodejs是什么? Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境.Node.js 使用了一个事件驱动.非阻塞式 I/O 的模型,使其轻量又高效. ...
- Upload files to aliyunOSS with bootstrap-fileinput
本文主要涉及两个概念: 阿里云OSS:对象存储(Object Storage Service,简称OSS),是阿里云对外提供的海量.安全和高可靠的云存储服务. bootstrap-fileinput: ...
- cs11_adventure c++_lab1
exercise1.cc #include <iostream> #include <vector> #include <stdlib.h> #include &l ...
- 登陆判读,并跳转到指定页面(window.location.href='http://localhost/index.html')
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 functio ...
- .NET获取根目录方法
1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径 方法2.AppDomain.CurrentDomain.Ba ...
- Python自动化 【第十五篇】:CSS、JavaScript 和 Dom介绍
本节内容 CSS javascript dom CSS position标签 fixed: 固定在页面的某个位置 relative + absolute: 相对定位 opacity:0.5 设置透明度 ...
- 一个C#语法高亮插件
语法高亮对程序员阅读代码来说有着不小的帮助,虽然VisualStudio本身支持C#语法高亮,但也只是对关键字.类名.字符串等少数元素加了标记,而我们代码中主题:变量.函数.属性.事件等都没有进行高亮 ...
- Permission denied:multiarray.cp35-win_amd64.pyd(tensorflow0.12.0在windows下安装)
今天在windows下安装tensorflow0.12.0. 碰到一个奇怪的问题.Permission denied:multiarray.cp35-win_amd64.pyd 就是复制文件,一直复制 ...