一。 Ad-hoc命令简介

1. 格式:ansible <host> [opion]

2. option参数:

-v:输出详细的执行过程, -vvv最详细的结果

-i:指定inventory的路径

-f:并发的线程数量,默认是5

-m:调用的模块

-u:  指令执行的账号

-b:调用sudo

3. 场景使用:

3.1 ansible all -f 5 -m ping

3.2 ansible proxy -s -m command -a 'hostname' -vvv

3.3 ansible web-list

3.4 time ansible 10.21.40.61 -B 5 -P 2 -T 2 -m command -a 'sleep 20' -u root

二。Ad-Hoc查看系统设置:

1. ansible app -a 'df -h'

2.ansible app -m shell -a 'free -m'

三。 Ad-Hoc的并发特性:

1.  -f 参数实现多线程

2. 并发数量为cpu核数的偶数倍,如 4core8GB的,最多配20个线程。

四。Ad-Hoc的模块使用:

1. 查询使用说明: ansible-doc

1.1 ansible-doc -l

1.2 ansible-doc yum

2. 场景:

2.1 安装redhat-lsb

ansible apps -m yum -a 'name=redhat-lsb state=present'

2.2 查看系统版本号:

ansible apps -m command -a 'lsb_release -a'

2.3 为所有机器安装ntp服务

ansible apps -s -m yum -a 'name=ntp state=present'

ansible apps -m service -a 'name=ntpd state=started enabled=yes'

五。特定主机的变更

1. --limit参数实现:

ansible app -m command -a 'service ntpd status' --limit '192.168.0.2'

2. 指定ip

ansible 192.168.0.2 -m command -a 'service ntpd status'

3. 用‘:’做分隔,多台:

ansible '192.168.0.2:192.168.0.3' -m command -a 'service ntpd status'

4. 通过‘*’,泛匹配

ansible 192.168.0.2* -m command -a 'service ntpd status'

六。用户及用户组管理

ansible--03的更多相关文章

  1. ansible 主机清单 /etc/ansible/hosts

    主机清单 [webservers] ansible01 ansible02 ansible03 ansible04 [root@ftp:/root] > ansible webservers - ...

  2. ansible自动化运维03

    ansible自动化运维常用模块 常用模块实现的功能:安装软件包:修改配置文件:创建程序用户组:创建目录,并修改所属和权限:挂载:启动服务:测试. command模块: shell模块: 注意:com ...

  3. 03: saltstack和ansible的区别和原理

    1.1 SaltStack.Ansible.Puppet比较 1.SaltStack 1. saltStack由Python编写,为server-client模式的系统,自己本身支持多master. ...

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

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

  5. 运维自动化之ansible的安装与使用(包括模块与playbook使用)(转发)

    原文  http://dl528888.blog.51cto.com/2382721/1435415 我使用过puppet(地址是http://dl528888.blog.51cto.com/2382 ...

  6. ansible网络模块安装httplib2

    ansible网络模块安装httplib2 在进行使用ansible的网络模块的时候,需要安装httplib2模块 下载地址: https://pypi.python.org/pypi?%3Aacti ...

  7. ansible安装(批量执行命令

    rpm安装 下载epl源 :  Download the latest epel-release rpm from:http://dl.fedoraproject.org/pub/epel/6/x86 ...

  8. 自动化运维工具之ansible

    自动化运维工具之ansible   一,ansible简介 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fab ...

  9. ansible小结

    一.Ansible的安装 1.yum源安装 以centos为例,默认在源里没有ansible,不过在fedora epel源里有ansible,配置完epel 源后,可以直接通过yum 进行安装.这里 ...

  10. Ansible 入门 (1) - 安装和配置

    本文参考 <Ansible 自动化运维和最佳实践>,这两天刚读这本书,写写总结.主控机环境是 centos 7,被控机均是 centos 6.8 . 确保 python 版本大于 2.6 ...

随机推荐

  1. 【转】从msql数据库处理高并发商品超卖

    今天王总又给我们上了一课,其实mysql处理高并发,防止库存超卖的问题,在去年的时候,王总已经提过:但是很可惜,即使当时大家都听懂了,但是在现实开发中,还是没这方面的意识.今天就我的一些理解,整理一下 ...

  2. Builder 设计模式的学习

    Buileder(生成器)—对象创建型模式 一 意图 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. 二 适用性 在以下情况使用Build模式: 1 当创建复杂对象的算法应 ...

  3. Ubuntu使用心得

    因为开发学习需要,也接触了一些Ubuntu系统,玩崩了两次系统之后,也学到了一些东西. -------------------------------------------------------- ...

  4. mysql索引类型normal,unique,full text的区别

    normal:表示普通索引 unique:表示唯一的,不允许重复的索引,如果该字段信息保证不会重复例如身份证号用作索引时,可设置为unique full textl: 表示 全文搜索的索引. FULL ...

  5. js判断移动端页面按home键切换到桌面事件

    ---恢复内容开始--- 原理就是通过页面标签切换事件(visibilitychange)来判断,亦可用户移动端桌面和app切换. 先看代码: var hiddenProperty = 'hidden ...

  6. Spring Boot—12URL映射

    package com.sample.smartmap.controller; import java.util.List; import org.springframework.beans.fact ...

  7. zookeeper应用 - 监控

    服务器端:监听zk上父节点的子节点变化 package monitor; import java.util.List; import java.util.concurrent.CountDownLat ...

  8. INFO: Font Metrics and the Use of Negative lfHeight

    INFO: Font Metrics and the Use of Negative lfHeight  Print  Email   Article translations  Article ID ...

  9. asp.net(C#)常用时间日期处理类

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  10. Week4——Hello.java分析

    如下图源码所示: 该段代码声明了一个entity实体类,该类有一个变量name,对该变量写了对应的get和set方法.类中还有一个空的构造方法hello(). @RequestScoped用于指定一个 ...