Ansible and FileBeta
使用Ansible通过ssh批量读取和修改Client设备
1. 安装ansible工具
apt-get install ansible
2. 添加需要访问的client信息
ansible配置文件如下
/etc/ansible/ansible.cfg
/etc/ansible/hosts
首先放开ansible.cfg中指定的hosts路径,然后编辑hosts如下:
[client]
x.x.x.x ansible_ssh_user="user_name" ansible_ssh_pass="user_pwd" ansible_ssh_port=
3. 安装sshpass
apt-get install sshpass
4. 执行命令
ansible client -m command -a "ls /root"
5. 用python在IP后添加ssh自动验证
#_*_coding:utf-8_*_ with open('client') as f_input:
lines=f_input.readlines()
with open('client_aaron', 'w') as f_output:
for line in lines:
f_output.write(line.replace(b'\n',b' ansible_ssh_user="usr_name" ansible_ssh_pass="usr_pwd" ansible_ssh_port=22\n')) f_input.close()
f_output.close()
问题:
1. 首次登陆需要对ssh进行校验,会导致上述命令报错如下
ERROR: 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.
参见http://www.361way.com/ansible-cfg/4401.html 关闭ansible.cfg中的host_key_checking功能
Ansible and FileBeta的更多相关文章
- 如何利用ansible callback插件对执行结果进行解析
最近在写一个批量巡检工具,利用ansible将脚本推到各个机器上执行,然后将执行的结果以json格式返回来. 如下所示: # ansible node2 -m script -a /root/pyth ...
- 《Ansible权威指南》笔记(2)——Inventory配置
四.Inventory配置ansible通过Inventory来定义主机和组,使用时通过-i指定读取,默认/etc/ansible/hosts.可以存在多个Inventory,支持动态生成.1.定义主 ...
- useful Ansible commands
This article includes some useful Ansible commands. I will try to write blogs by English. You may wa ...
- 《Ansible权威指南》笔记(4)——Playbook
七.Playbook1.语法特性如下:(1)"---"首行顶格开始(2)#号注释(3)缩进统一,不同的缩进代表不同的级别,缩进要对齐,空格和tab不能混用(4)区别大小写,键值对k ...
- 《Ansible权威指南》笔记(3)——Ad-Hoc命令集,常用模块
五.Ad-Hoc命令集1.Ad-Hoc命令集通过/usr/bin/ansible命令实现:ansible <host-pattern> [options] -v,--verbose ...
- 《Ansible权威指南》笔记(1)——安装,ssh密钥登陆,命令
2016-12-23 读这本<Ansible权威指南>学习ansible,根据本书内容和网上的各种文档,以及经过自己测试,写出以下笔记.另,这本书内容很好,但印刷错误比较多,作者说第二版会 ...
- 自动化运维工具ansible部署以及使用
测试环境master 192.168.16.74webserver1 192.168.16.70webserver2 192.168.16.72安装ansiblerpm -Uvh http://ftp ...
- Ansible Ubuntu 安装部署
一.安装: $ sudo apt-get install ansible 二.配置: a.基本配置 $ cd /etc/ansible/ $ sudo cp hosts hosts_back 备份一个 ...
- Ansible 模块命令介绍
copy模块: 目的:把主控端/root目录下的a.sh文件拷贝到到指定节点上 命令:ansible 10.1.1.113 -m copy -a 'src=/root/a.sh dest=/tmp/' ...
随机推荐
- Spring 自动定时任务配置
Spring中可以通过配置方便的实现周期性定时任务管理,这需要用到以下几个类: org.springframework.scheduling.quartz.MethodInvokingJobDetai ...
- C#:几种数据库的大数据批量插入(转)
在之前只知道SqlServer支持数据批量插入,殊不知道Oracle.SQLite和MySql也是支持的,不过Oracle需要使用Orace.DataAccess驱动,今天就贴出几种数据库的批量插入解 ...
- php创建udp Server
<?php//服务器信息$server = 'udp://127.0.0.1:7002';//----UDP Server$msgEof = "\n";$socket = s ...
- bzoj 4737: 组合数问题
Description 组合数C(n,m)表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3)三个物品中选择两个物品可以有( 1,2),(1,3),(2,3)这三种选择方法.根据组合数 ...
- 20172302 《Java软件结构与数据结构》第七周学习总结
2018年学习总结博客总目录:第一周 第二周 第三周 第四周 第五周 第六周 第七周 教材学习内容总结 第11章 二叉查找树 1.二叉查找树是一种含有附加属性的二叉树,该属性即其左孩子小于父节点,而父 ...
- AppleScript脚本学习记录《一》
tell命令块 tell application "Finder" display dialog "Hello World" end tell 声明变量 set ...
- JProfiler远程监控
1. 服务端安装JProfiler(与客户端版本一致) 2. 客户端配置连接: A).session——integration wizards——New remote integration B) ...
- 微信小程序 scroll-view 实现锚点跳转
在微信小程序中,使用 scroll-view 实现长页面的标记跳转,官方文档中没有例子演示,锚点标记主要是使用<scroll-view> 的 scroll-into-view 属性. 实现 ...
- 回顾2018年最受欢迎的十四款NoSQL产品
虽然NoSQL的流行与火起来才短短一年的时间,但是不可否认,现在已经开始了第二代运动.尽管早期的堆栈代码只能算是一种实验,然而现在的系统已经更加的成熟.稳定.不过现在也面临着一个严酷的事实:技术越 ...
- ThinkPhp 更改 BIT 类型的问题
在使用ThinkPhp更改字段为BIT 类型的注意了,您将会遇到以下错误信息: 这是因为ThinkPhp在使用setField或Save方法时,将你的值更改成了字符串类型 而TINYINT 类型是不 ...