ansible之command和raw模块
2016-05-02 13:37
267 查看
command模块
command模块为ansible默认模块,不指定-m参数时,使用的就是command模块;comand模块比较简单,常见的命令都可以使用,但其命令的执行不是通过shell执行的,所以,像这些 "<", ">", "|", and "&"操作都不可以,运行中的命令不支持变量使用以及不支持管道;
示例:显示当前用户
[root@ansible ~]# ansible all -a 'whoami' db | SUCCESS | rc=0 >> root web | SUCCESS | rc=0 >> root 192.168.33.132 | SUCCESS | rc=0 >> rootcommand用法
[root@ansible ~]# ansible-doc -s command less 436 Copyright (C) 1984-2009 Mark Nudelman less comes with NO WARRANTY, to the extent permitted by law. For information about the terms of redistribution, see the file named README in the less distribution. Homepage: http://www.greenwoodsoftware.com/less - name: Executes a command on a remote node action: command chdir # cd into this directory before running the command creates # a filename or (since 2.0) glob pattern, when it already exists, this step will *not* be run. executable # change the shell used to execute the command. Should be an absolute path to the executable. free_form= # the command module takes a free form command to run. There is no parameter actually named 'free form'. See the examples! removes # a filename or (since 2.0) glob pattern, when it does not exist, this step will *not* be run. warn # if command warnings are on in ansible.cfg, do not warn about this particular line if set to no/false.
- name: 在远程节点执行命令
action: command
chdir # 在执行命令之前,先切换到该目录
creates # 一个文件名,当这个文件存在,则该命令不执行
executable # 切换shell来执行命令,需要使用命令的绝对路径
free_form= #要执行的Linux指令,一般使用Ansible的-a参数代替。
removes #一个文件名,这个文件不存在,则该命令不执行
raw,类似command,但可以传递管道用法
[root@ansible ~]# ansible-doc -s raw less 436 Copyright (C) 1984-2009 Mark Nudelman less comes with NO WARRANTY, to the extent permitted by law. For information about the terms of redistribution, see the file named README in the less distribution. Homepage: http://www.greenwoodsoftware.com/less - name: Executes a low-down and dirty SSH command action: raw executable # change the shell used to execute the command. Should be an absolute path to the executable. free_form= # the raw module takes a free form command to run
示例,查看web服务器上swap状态
[root@ansible ~]# ansible web -m raw -a 'free -m|grep Swap' web | SUCCESS | rc=0 >> Swap: 2047 0 2047
相关文章推荐
- 基于 ANSIBLE 自动化运维实践
- 链路故障排查记
- Linux任务前后台的切换
- Perl模块编写说明
- 在Lua中使用模块的基础教程
- Lua模块与包学习笔记
- Erlang中的模块与模式匹配介绍
- asp中command的在单条记录时,有些字段显示为空的问题
- Delphi Command模式
- Ruby中使用SWIG编写ruby扩展模块实例
- Ruby中关于模块的一些基础知识
- Lua中的模块与module函数详解
- JavaScript模块规范之AMD规范和CMD规范
- apache rewrite_module模块使用教程
- ThinkPHP采用模块和操作分析
- Lua cjson模块编译笔记及错误解决方法
- linux下php加装mssql模块的方法
- php设计模式 Command(命令模式)
- 开启Apache mod_rewrite模块示例代码
- 解决bash: mysql: command not found 的方法