Ansible 笔记 (2) - Ad-hoc 命令
先使用 ansible-doc 获取帮助文档
[root@localhost ~]# ansible-doc ping
> PING (/usr/lib/python2.7/site-packages/ansible-2.3.0-py2.7.egg/ansible/modules/system/ping.py) A trivial test module, this module always returns `pong' on successful contact. It does not make sense in
playbooks, but it is useful from `/usr/bin/ansible' to verify the ability to login and that a usable python is
configured. This is NOT ICMP ping, this is just a trivial test module. EXAMPLES:
# Test we can logon to 'webservers' and execute python with json lib.
ansible webservers -m ping MAINTAINERS: Ansible Core Team, Michael DeHaan METADATA:
Status: ['stableinterface']
Version: 1.0
Supported_by: core
命令格式 Usage: ansible <host-pattern> [options]
- 显示 hosts
[root@localhost ~]# ansible all --list-hosts
hosts (2):
192.168.34.129
192.168.34.130
[root@localhost ~]# ansible webserver --list-hosts
hosts (2):
192.168.34.129
192.168.34.130
[root@localhost ~]# ansible 192.168.34.129:192.168.34.130 --list-hosts
hosts (2):
192.168.34.129
192.168.34.130
- 指定 inventory(hosts) 执行命令,使用 ansible -m 指定模块 -a 指定参数 -o 单行输出
[root@localhost ~]# ansible all -m ping
192.168.34.130 | SUCCESS => {
"changed": false,
"ping": "pong"
}
192.168.34.129 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[root@localhost ~]# ansible webserver -m ping
192.168.34.129 | SUCCESS => {
"changed": false,
"ping": "pong"
}
192.168.34.130 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[root@localhost ~]# ansible 192.168.34.129 -m ping
192.168.34.129 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[root@localhost ~]# ansible 192.168.34.129:192.168.34.130 -m ping
192.168.34.129 | SUCCESS => {
"changed": false,
"ping": "pong"
}
192.168.34.130 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[root@localhost ~]# ansible 192.168.34.129:192.168.34.130 -m command -a uptime -o
192.168.34.129 | SUCCESS | rc= | (stdout) :: up :, users, load average: 0.08, 0.13, 0.13
192.168.34.130 | SUCCESS | rc= | (stdout) :: up :, users, load average: 0.14, 0.10, 0.09
-m 默认模块是 command,这里可以忽略。同时我们可以自己编写脚本指定“动态 inventory”,具体的写法请自行百度。这个脚本需要支持两个参数, --list/-l 和 --host/-H,并且返回 json 格式的数据。
- 需要注意的是如果“被控机”开启了 selinux,则在使用 copy 模块时需要在“被控机”上安装 libselinux-python,才能保证正常执行 copy 模块
Ansible 笔记 (2) - Ad-hoc 命令的更多相关文章
- ansible笔记(6):常用模块之命令类模块
ansible笔记():常用模块之命令类模块 command模块 command模块可以帮助我们在远程主机上执行命令 注意:使用command模块在远程主机中执行命令时,不会经过远程主机的shell处 ...
- 未打开Ad Hoc Distributed Queries
SSAS访问ORACLE数据仓库读取数据创建CUBE的时候报如下错误: SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'Open ...
- ansible笔记(12):handlers的用法
ansible笔记():handlers的用法 这篇文章会介绍playbook中handlers的用法. 在开始介绍之前,我们先来描述一个工作场景: 当我们修改了某些程序的配置文件以后,有可能需要重启 ...
- ansible笔记(10):初识ansible playbook
ansible笔记():初识ansible playbook 假设,我们想要在test70主机上安装nginx并启动,我们可以在ansible主机中执行如下3条命令 ansible test70 -m ...
- ansible笔记(7):常用模块之系统类模块
ansible笔记():常用模块之系统类模块 cron模块 cron模块可以帮助我们管理远程主机中的计划任务,功能相当于crontab命令. 在了解cron模块的参数之前,先写出一些计划任务的示例,示 ...
- ansible笔记(8):常用模块之系统类模块(二)
ansible笔记():常用模块之系统类模块(二) user模块 user模块可以帮助我们管理远程主机上的用户,比如创建用户.修改用户.删除用户.为用户创建密钥对等操作. 此处我们介绍一些user模块 ...
- ansible笔记(9):常用模块之包管理模块
ansible笔记():常用模块之包管理模块 yum_repository模块 yum_repository模块可以帮助我们管理远程主机上的yum仓库. 此处我们介绍一些yum_repository模 ...
- ansible笔记(5):常用模块之文件操作(二)
ansible笔记():常用模块之文件操作(二) 文件操作类模块 find模块 find模块可以帮助我们在远程主机中查找符合条件的文件,就像find命令一样. 此处我们介绍一些find模块的常用参数, ...
- ansible笔记(3):ansible模块的基本使用
ansible笔记():ansible模块的基本使用 在前文的基础上,我们已经知道,当我们使用ansible完成实际任务时,需要依靠ansible的各个模块,比如,我们想要去ping某主机,则需要使用 ...
- ansible笔记(1)在centos中安装ansible
ansible笔记():ansible的基本概念 一些基础概念 ansible是什么? 它是一个"配置管理工具",它是一个"自动化运维工具",如果你没有使用过任 ...
随机推荐
- 【转】在Visual Studio中怎样快速添加代码段
原文网址:http://blog.csdn.net/yl2isoft/article/details/9735527 以前一直只知道,键入prop,再按两次tab键,会生成自动属性代码. 今天闲着无事 ...
- docker基于commit命令创建支持ssh服务的镜像
以centos为基础,目的使用ssh服务远程连接docker容器. 环境:宿主机centos7(宿主机ip地址为192.168.164.130),直接搜索docker的centos镜像,下载最新版本. ...
- [C++ Primer] 第8章: IO库
IO类 iostream定义了读写流的基本类型 istream, wistream 从流读取数据 ostream, wostream 向流写入数据 iostream, wiostream 读写流 fs ...
- thinkpad t420安装debian需要注意的细节
关闭双显卡,使用集成显卡,32位可以用独显跑起来,但是64位的wheezy只能兼容集成显卡,不知道为啥,否则会在某些usb插入/或者拔出来以后,重启提示 failed to execute /lib/ ...
- [html][javascript] 正则匹配示例
var str="akdlfaklhello 1234klfd1441ksalfd9000kals8998j2345fd;lsa"; var reg = new RegExp(/( ...
- Ruby中数组的遍历
转自:http://www.jianshu.com/p/8de9b60f9350 Ruby中有几个常用的遍历数组的方法,本人经常容易搞混.这里列出来总结一下. each: 从数组中取出一个元素,作为某 ...
- [maven] 实战笔记 - maven 安装配置
1.下载地址http://maven.apache.org/download.html 2.windows下安装maven(1)下载 apache-maven-3.0-bin.zip 解压到任意目录下 ...
- php执行linux函数
function B(){ if(defined('LOCK') && LOCK == 'lock') return false; $addPort = sprintf('-A INP ...
- VB.NET条码机打印设置纸张大小的方法
Imports System.Drawing.PrintingImports System.Runtime.InteropServices Public Class Page <Runti ...
- 学习IIS & MVC的运行原理 (转)
我一直疑惑于以下问题,从客户端发出一个请求,请求到达服务器端是怎样跟iis衔接起来的,而iis又是怎样读取我发布的代码的,并返回服务器上的文件.这其中是怎样的一个处理过程. 1:当你从浏览器中输入一个 ...