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是什么? 它是一个"配置管理工具",它是一个"自动化运维工具",如果你没有使用过任 ...
随机推荐
- errno.h的数字对应的字符串错误
#ifndef _I386_ERRNO_H #define _I386_ERRNO_H #define EPERM 1 /* Operation not permitted */ #define EN ...
- node.js + express 初体验【hello world】
[node.js] 一个神奇的XX 呵呵 :) 不知道怎么形容他才好! [express] 是node.js 开发web应用程序的框架 开发环境:XP 大家共同进步吧 :) 一:前期准备: 1:下载 ...
- 基数排序算法-python实现
#-*- coding: UTF-8 -*- import numpy as np def RadixSort(a): i = 0 #初始为个位排序 n = 1 #最小的位数置为1(包含0) max ...
- erlang程序发布的时候需要注意的地方
假如你的程序依赖三方application,比如cowboy,启动三方程序有两种方式 在erl脚本里面手工启动,这种在使用rebar generate打包的时候和发布beam的时候都可以用 appli ...
- ubuntu安装tushare
sudo apt-get install python-pandas sudo pip install tushare
- ElasticSearch 基础概念学习(未完)
1.基本定义 摘自百度百科 elasticseaElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elastic ...
- 记录在Python2.7 x64 bit 下 PyQt5.8的编译过程
由于工作需要使用python下面的Qt库.PyQt现在只提供针对Python3.X系列的PyQt,所有需要自己手动编译.防止忘记,特意写下随笔记录备忘. 工 作 环境:Python版本:Python ...
- ASP.NET中的几种弹出框提示基本实现方法
我们在.NET程序的开发过程中,常常需要和用户进行信息交互,比如执行某项操作是否成功,“确定”还是“取消”,以及选择“确定”或“取消”后是否需要跳转到某个页面等,下面是本人对常用对话框使用的小结,希望 ...
- tesseract-ocr训练方法
tesseract-ocr有2和3两个版本,不同版本训练方法稍有不同. 第3版本的训练方法官版教程在这里:TrainingTesseract3 第2版的训练方法官版教程在这里:TrainingTess ...
- MyEclipse编译报:javaScript Validator错误
转自:https://blog.csdn.net/lkpmemory/article/details/8833329 Myeclipse编译报错如下: Errors occurred during t ...