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是什么? 它是一个"配置管理工具",它是一个"自动化运维工具",如果你没有使用过任 ...
随机推荐
- 1.Appium环境搭建
1.安装node.js (1)去node官网下载,根据操作系统的不同选择不同对应的版本(https://nodejs.org/en/download/) (2)下载对应的版本后进行安装,一直下一步直至 ...
- C#使用WebService
一.新建webservice 新建项目→asp.net Web服务应用程序 或者在现有项目中 点击右键 新建web服务程序asmx 只要在webservice类里面 的方法 标注为[WebMethod ...
- Log4j(3)--rootLogger根配置和appender输出类型配置
参考博客:http://blog.java1234.com/blog/articles/270.html 一.rootLogger根配置: Log4j 根配置语法 log4j.rootLogger = ...
- Linux C 一些函数 所属的头文件
在编写程序时,有时总是不记得所使用的函数在哪个库函数中.现在先把自己以前经常用到的函数头文件总结一下. 有不对的地方还请指教. 1,系统调用文件的操作函数 #inlclude <fcntl.h& ...
- php删除制定文件及文件夹
php遍历一个文件夹内的所有文件和文件夹,并删除所有文件夹和子文件夹下的所有文件的代码,通过递归方式实现达到清空一个目录的效果,代码简单实用. 用到的函数: scandir($path) 遍历一个文件 ...
- mkdir 权限值注意要用八进制表示,即“0”开头,而且一定不要加引号http://php.net/manual/en/function.mkdir.php
- springcloud(四) ribbon和feign
Ribbon使用 order-service工程: application.yml: server: port: 9010 #order 服务都是用90 开头的端口 spring: applicati ...
- mock 的独立使用
public class Air21QueryMileStoneJobTest{ @InjectMocks Air21QueryMileStoneJob air21QueryMileStoneJob ...
- call apply 使用
1.call 跟 apply的主要区别: call传入参数是一个一个传入,而 apply 使用的是数组传入 call(obj,arg1,arg2,arg3,arg4) apply(obj,[arg1, ...
- 基于Windows 配置 nginx 集群 & 反向代理
1.下载 nginx 下载页面 : http://nginx.org/en/download.html 具体文件: http://nginx.org/download/nginx-1.7.0.zip ...