使用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. python 中的可变对象与不可变对象

    近日辞职待工,没有实际的项目与大家分享.暂写写在实际运用python中遇到的关于可变对象和不可变对象的坑. 首先我们需要明确一个概念,在python中一且皆对象.我们一般定义一个变量a=0,其实质a是 ...

  2. CSS-定位(Position)

    目录 CSS-定位(Position) CSS-定位(Position) ### 学习自 菜鸟教程 ### Overview CSS中HTML元素存在以下之后定位选项 Position Desc st ...

  3. Python3 里面的线程池

    from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor import time def task(i): print ...

  4. Python3自然语言(NLTK)——语言大数据

    NLTK 这是一个处理文本的python库,我们知道文字性的知识可是拥有非常庞大的数据量,故而这属于大数据系列. 本文只是浅尝辄止,目前本人并未涉及这块知识,只是偶尔好奇,才写本文. 从NLTK中的b ...

  5. java的关键字与保留字

    1,Java 关键字列表 (依字母排序 共50组): abstract, assert, boolean, break, byte, case, catch, char, class, const(保 ...

  6. Django拾遗--pagination、sitemap、admin、form

    Django拾遗--pagination.sitemap.admin.form pagination 其实这个分页模块的原理就是根据设定的每页条数来分割queryset.查询结果/每页子项数目=页数 ...

  7. Android跨进程通信:图文详解 Binder机制 原理

    binder原理讲的很详细 https://blog.csdn.net/carson_ho/article/details/73560642

  8. c# sqlite 数据库加密

    c# sqlite 数据库加密 2010-05-29 10:55 用了ADO.NET 2.0 SQLite Data Provider这样可以直接利用它来创建一个加密的sqlite数据库.有关c#代码 ...

  9. springboot之启动原理解析及源码阅读

    前言 SpringBoot为我们做的自动配置,确实方便快捷,但是对于新手来说,如果不大懂SpringBoot内部启动原理,以后难免会吃亏.所以这次博主就跟你们一起一步步揭开SpringBoot的神秘面 ...

  10. IntelliJ_2017_安装Grep Console插件(console输出内容加颜色)

      官网下载:https://plugins.jetbrains.com/plugin/7125-grep-console   一.安装Grep Console插件     二.设置不同日志类型的不同 ...