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是什么? 它是一个"配置管理工具",它是一个"自动化运维工具",如果你没有使用过任 ...
随机推荐
- windows7安装django并创建第一个应用
1.安装django 1.1.下载Django包 https://www.djangoproject.com/download/https://www.djangoproject.com/m/rele ...
- Oracle本地网络服务名配置
1.安装Oracle 11G Client后可以在开始菜单中找到 选择NETCA->本地网络服务名配置 选择添加本地网服务名配置 这里的服务名:指的是也就是数据库名 在网络中架设C/S 客户端选 ...
- java操作word报错及解决办法
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jacob-1.17-x86 in java.libra ...
- 黄聪:wordpress如何防止发布文章时候自动清除<P>、<br>换行标签
1.安装[TinyMCE Advanced]插件 2.进入[后台]--[设置]--[TinyMCE Advanced]把这个选项勾上保存即可.
- web攻击之一:XSS跨站脚本
一.浏览器安全 同源策略 影响源的因素:host,子域名,端口,协议 a.com通过以下代码: <script scr=http://b.com/b.js> 加载了b.com上的b.js, ...
- HDU 4762 Cut the Cake(高精度)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- Codeforces Round #474-B(贪心)
一.题目链接 http://codeforces.com/contest/960/problem/B 二.题意 给定三个数字$N, k1, k2$,接下来给出两组数$a[]$和$b[]$,每组数$N$ ...
- Microsoft SQL Server on Linux破解 2G内存限制
首先,贴上微软官方安装方法,大家按照官方的操作就行. 微软官方安装方法 相信很多同学遇到一个问题就是: sqlservr: This program requires a machine with a ...
- java工具库
Guava: commons:---工具库(尤其里面的排序库) joda-time:
- django关于静态的信息的配置
今天搭建完,django后,访问 admin 发现 样式没有加载 需要搭建静态的配置 1 设置项目目录的静态目录 用来存放静态的文件 在setttings.py中 添加以下参数 在 STATIC_ ...