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/' ...
随机推荐
- 基于URL的高层次Java网络编程
一致资源定位器URL URL(Uniform Resource Locator)是一致资源定位器的简称,它表示Internet上某一资源的地址.通过URL我们可以访问Internet上的各种网络资源, ...
- python+imageMagick写的一个压缩图片脚本
!/usr/bin/python import os import cPickle as p import re import Image def imageCompre(imagedir = '.' ...
- [CF896C]Willem, Chtholly and Seniorious(珂朵莉树)
https://www.cnblogs.com/WAMonster/p/10181214.html 主要用于支持含有较难维护的区间操作与查询的问题,要求其中区间赋值操作(assign())是纯随机的. ...
- Python3基础之字典
Python数据类型之字典(Dictionary) 字典特征 特征 可变.无序.映射.键值对 形式 {key0:value0, key1:value1, key2:value3, ..., } key ...
- [USACO 102]Agri-Net
OJ题号:POJ1258.洛谷1546 思路:Kruskal. #include<cstdio> #include<utility> #include<vector> ...
- Chrome 浏览器的Secure Shell插件
说起putty,windows下面的程序猿个个都是爱恨交加. 不小心发现一个宝贝,Chrome 浏览器的Secure Shell插件. 这是Google官方推出的插件,试用下来,putty完全可以下岗 ...
- python 元组和字典中元素作为函数调用参数传递
模式1. def test1(*args): test3(*args) def test2(**kargs): test3(**kargs) def test3(a, b): print(a,b) ...
- 2d场景背景无限滚动
之前都是直接借用的DoTween插件,两个背景无限交替位置进行,还有就是三个背景在利用Trigger进行判断显示与否循环: 示例脚本: private List<RectTransform> ...
- C#的?和??
1.?? 为了实现Nullable数据类型转换成non-Nullable类型数据,才有的一个操作符: 意义:一变量取值,取符号左边的值,若左边为null,那么取赋值??右边的: 栗子:int a=3 ...
- og4j日志文件乱码问题的解决方法
现象:在默认语言非中文(或者说默认语言不支持中文的)的Windows.Linux.Unix上,用log4j打印日志,出现乱码,常见的就是一堆问号. 解决方法: 如果是log4j.properties为 ...