ansible常用模块介绍:command&&raw

简介

上文介绍了ansible的shell模块,今天要为大家分享的是command模块和raw模块的使用。

command和raw模块和shell一样,都是用于执行shell命令,三者都不具备幂等性,如果有能替代的ansible模块,尽量不要说使用该模块。

对比

模块用途特点
shell均用于执行shell模块可以使用环境变量,也可以使用变量和操作符(例如 '|', '<', '>', '&')
commandcommand不可以使用环境变量,也支持变量操作符,相对shell安全一些
raw被执行机器上没安装python环境也可以执行,直接使用shell

帮助

command模块

ansible-doc -s command
- 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.

raw模块

ansible-doc -s raw
- 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. when using privilege escalation
(`become'), a default shell will be assigned if one is not provided as privilege escalation
requires a shell.
free_form= # the raw module takes a free form command to run

command和raw模块的参数和shell一致,具体可以参考shell

例子

可以将前文shell模块例子部分的-m shell换成-m command或者-m raw。

例如

ansible -i /etc/ansible/hosts local -m command -a 'pwd'
ansible -i /etc/ansible/hosts local -m raw -a 'pwd'

有任何疑问和建议,请在下方留言~

传送门:2021最新测试资料与大厂招聘合集

博主:测试生财(一个不为996而996的测开码农)

座右铭:专注测试开发与自动化运维,努力读书思考写作,为内卷的人生奠定财务自由。

内容范畴:技术提升,职场杂谈,事业发展,阅读写作,投资理财,健康人生。

csdn:https://blog.csdn.net/ccgshigao

博客园:https://www.cnblogs.com/qa-freeroad/

51cto:https://blog.51cto.com/14900374

微信公众号:测试生财(定期分享独家内容和资源)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

公众号-测试生财

点赞和关注比打赏更重要

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值