使用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的更多相关文章

  1. 如何利用ansible callback插件对执行结果进行解析

    最近在写一个批量巡检工具,利用ansible将脚本推到各个机器上执行,然后将执行的结果以json格式返回来. 如下所示: # ansible node2 -m script -a /root/pyth ...

  2. 《Ansible权威指南》笔记(2)——Inventory配置

    四.Inventory配置ansible通过Inventory来定义主机和组,使用时通过-i指定读取,默认/etc/ansible/hosts.可以存在多个Inventory,支持动态生成.1.定义主 ...

  3. useful Ansible commands

    This article includes some useful Ansible commands. I will try to write blogs by English. You may wa ...

  4. 《Ansible权威指南》笔记(4)——Playbook

    七.Playbook1.语法特性如下:(1)"---"首行顶格开始(2)#号注释(3)缩进统一,不同的缩进代表不同的级别,缩进要对齐,空格和tab不能混用(4)区别大小写,键值对k ...

  5. 《Ansible权威指南》笔记(3)——Ad-Hoc命令集,常用模块

    五.Ad-Hoc命令集1.Ad-Hoc命令集通过/usr/bin/ansible命令实现:ansible <host-pattern> [options]    -v,--verbose  ...

  6. 《Ansible权威指南》笔记(1)——安装,ssh密钥登陆,命令

    2016-12-23 读这本<Ansible权威指南>学习ansible,根据本书内容和网上的各种文档,以及经过自己测试,写出以下笔记.另,这本书内容很好,但印刷错误比较多,作者说第二版会 ...

  7. 自动化运维工具ansible部署以及使用

    测试环境master 192.168.16.74webserver1 192.168.16.70webserver2 192.168.16.72安装ansiblerpm -Uvh http://ftp ...

  8. Ansible Ubuntu 安装部署

    一.安装: $ sudo apt-get install ansible 二.配置: a.基本配置 $ cd /etc/ansible/ $ sudo cp hosts hosts_back 备份一个 ...

  9. Ansible 模块命令介绍

    copy模块: 目的:把主控端/root目录下的a.sh文件拷贝到到指定节点上 命令:ansible 10.1.1.113 -m copy -a 'src=/root/a.sh dest=/tmp/' ...

随机推荐

  1. Linux开源监控平台 -- Zabbix 小白安装以及使用

    安装准备: 1.安装前需要先关闭selinux和firewall. 关闭Linux: [root@zabbix ~]# vi /etc/selinux/config 将SELINUX=enforcin ...

  2. jquery监听input元素输入

    一般我们监听input内容的变化都是通过onchange()事件来绑定,但这个做法有一个缺陷就是只有当正在被输入的input元素失去焦点时(即鼠标点击了别处)才会触发,而实际上我们往往希望能够满足在用 ...

  3. u3d 鼠标点击位置,物体移动过去。 U3d mouse clicks position, objects move past.

    u3d 鼠标点击位置,物体移动过去. U3d mouse clicks position, objects move past. 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱: ...

  4. jsp导出简单的excel

    在jsp中加入以下代码即可 <% String fileName = "导出excel.xls"; fileName = new String(fileName.getByt ...

  5. rabbitmq使用方法(一)

    Introduction RabbitMQ is a message broker. The principal idea is pretty simple: it accepts and forwa ...

  6. Redis集群方案总结

    Redis集群方案总结 Redis集群方案总结Codis其余方案Redis cluster 目前,Redis中目前集群有以下几种方案: 主从复制 哨兵模式 redis cluster 代理 codis ...

  7. 喵哈哈村的魔法考试 Round #14 (Div.2) 题解

    喵哈哈村的四月半活动(一) 题解: 唯一的case,就是两边长度一样的时候,第三边只有一种情况. #include <iostream> #include <cstdio> # ...

  8. C++ operator重载运算符和隐式转换功能的实现

    C++ operator重载运算符和隐式转换功能的实现: #include <iostream> using namespace std; class OperatorTest { pub ...

  9. 跟着ZooKeeper学Java——CountDownLatch和Join的使用

    在阅读ZooKeeper的源码时,看到这么一个片段,在单机模式启动的时候,会调用下面的方法,根据zoo.cfg的配置启动单机版本的服务器: public void runFromConfig(Serv ...

  10. STM32 逐次逼近寄存器型(SAR)模拟数字转换器(ADC)

    是采样速率低于5Msps (每秒百万次采样)的中等至高分辨率应用的常见结构. SAR ADC的分辨率一般为8位至16位,具有低功耗.小尺寸等特点. 这些特点使该类型ADC具有很宽的应用范围,例如便携/ ...