博主:测试生财
座右铭:专注测试与自动化,致力提高研发效能;通过测试精进完成原始积累,通过读书理财奔向财务自由。
csdn:https://blog.csdn.net/ccgshigao
标签:VID default 效能 orm content 介绍 target require hang
上文介绍了ansible的shell模块,今天要为大家分享的是command模块和raw模块的使用。
command和raw模块和shell一样,都是用于执行shell命令,三者都不具备幂等性,如果有能替代的ansible模块,尽量不要说使用该模块。
模块 | 用途 | 特点 |
shell | 均用于执行shell模块 | 可以使用环境变量,也可以使用变量和操作符(例如 ‘|‘, ‘<‘, ‘>‘, ‘&‘) |
command | command不可以使用环境变量,也支持变量操作符,相对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‘
有任何疑问和建议,请在下方留言~
博主:测试生财
座右铭:专注测试与自动化,致力提高研发效能;通过测试精进完成原始积累,通过读书理财奔向财务自由。
csdn:https://blog.csdn.net/ccgshigao
标签:VID default 效能 orm content 介绍 target require hang
原文地址:https://www.cnblogs.com/qa-freeroad/p/13941580.html