天天看點

ansible常用子產品介紹:command&&raw

簡介

上文介紹了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'      

有任何疑問和建議,請在下方留言~

快送門:各種學習資料與大廠招聘

部落客:測試生财(一個不為996而996的測開碼農)

座右銘:專注測試開發與自動化運維,努力讀書思考寫作,為内卷的人生奠定财務自由。

内容範疇:技術提升,職場雜談,事業發展,閱讀寫作,投資理财,健康人生。

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

部落格園:https://www.cnblogs.com/qa-freeroad/

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

繼續閱讀