ansible command苛骨、shell篱瞎、script、raw的區(qū)別

  1. command:執(zhí)行遠(yuǎn)程命令
    ansible -s -i hosts localhost -m command -a "df -h ."
  2. shell:執(zhí)行遠(yuǎn)程腳本(shell/pyhton)
    ansible -s -i hosts localhost -m shell -a "/etc/test.sh"
  3. script:在遠(yuǎn)程服務(wù)器上執(zhí)行本地腳本
    ansible -s -i hosts localhost -m script -a "/etc/test.sh"
  4. raw: 和command 功能相似智袭,支持管道符
    ansible -s -i hosts localhost -m raw -a "df -h . | tail -n1"

raw 文檔:

> RAW    (/usr/lib/python2.7/site-packages/ansible/modules/commands/raw.py)

        Executes a low-down and dirty SSH command, not going through the module subsystem. This is useful and should only be done in
        two cases. The first case is installing `python-simplejson' on older (Python 2.4 and before) hosts that need it as a dependency
        to run modules, since nearly all core modules require it. Another is speaking to any devices such as routers that do not have
        any Python installed. In any other case, using the [shell] or [command] module is much more appropriate. Arguments given to
        `raw' are run directly through the configured remote shell. Standard output, error output and return code are returned when
        available. There is no change handler support for this module. This module does not require python on the remote system, much
        like the [script] module. This module is also supported for Windows targets.

  * note: This module has a corresponding action plugin.

OPTIONS (= is mandatory):

- 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.
        [Default: (null)]
        version_added: 1.0

= free_form
        the raw module takes a free form command to run. There is no parameter actually named 'free form'; see the examples!



NOTES:
      * If using raw from a playbook, you may need to disable fact gathering using `gather_facts: no' if you're using `raw' to
        bootstrap python onto the machine.
      * If you want to execute a command securely and predictably, it may be better to use the [command] or [shell] modules
        instead.
      * the `environment' keyword does not work with raw normally, it requires a shell which means it only works if `executable'
        is set or using the module with privilege escalation (`become').
      * This module is also supported for Windows targets.

AUTHOR: Ansible Core Team, Michael DeHaan
        METADATA:
          status:
          - stableinterface
          supported_by: core


EXAMPLES:
- name: Bootstrap a legacy python 2.4 host
  raw: yum -y install python-simplejson

- name: Bootstrap a host without python2 installed
  raw: dnf install -y python2 python2-dnf libselinux-python

- name: Run a command that uses non-posix shell-isms (in this example /bin/sh doesn't handle redirection and wildcards together but bash does)
  raw: cat < /tmp/*txt
  args:
    executable: /bin/bash

- name: safely use templated variables. Always use quote filter to avoid injection issues.
  raw: "{{package_mgr|quote}} {{pkg_flags|quote}} install {{python_simplejson|quote}}"
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末奔缠,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子吼野,更是在濱河造成了極大的恐慌校哎,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,635評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件瞳步,死亡現(xiàn)場離奇詭異闷哆,居然都是意外死亡,警方通過查閱死者的電腦和手機单起,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,543評論 3 399
  • 文/潘曉璐 我一進店門抱怔,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人嘀倒,你說我怎么就攤上這事屈留【直” “怎么了?”我有些...
    開封第一講書人閱讀 168,083評論 0 360
  • 文/不壞的土叔 我叫張陵灌危,是天一觀的道長康二。 經(jīng)常有香客問我,道長勇蝙,這世上最難降的妖魔是什么沫勿? 我笑而不...
    開封第一講書人閱讀 59,640評論 1 296
  • 正文 為了忘掉前任,我火速辦了婚禮味混,結(jié)果婚禮上产雹,老公的妹妹穿的比我還像新娘。我一直安慰自己翁锡,他們只是感情好蔓挖,可當(dāng)我...
    茶點故事閱讀 68,640評論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著盗誊,像睡著了一般时甚。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上哈踱,一...
    開封第一講書人閱讀 52,262評論 1 308
  • 那天,我揣著相機與錄音梨熙,去河邊找鬼开镣。 笑死,一個胖子當(dāng)著我的面吹牛咽扇,可吹牛的內(nèi)容都是我干的邪财。 我是一名探鬼主播,決...
    沈念sama閱讀 40,833評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼质欲,長吁一口氣:“原來是場噩夢啊……” “哼树埠!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起嘶伟,我...
    開封第一講書人閱讀 39,736評論 0 276
  • 序言:老撾萬榮一對情侶失蹤怎憋,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后九昧,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體绊袋,經(jīng)...
    沈念sama閱讀 46,280評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,369評論 3 340
  • 正文 我和宋清朗相戀三年铸鹰,在試婚紗的時候發(fā)現(xiàn)自己被綠了癌别。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,503評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡蹋笼,死狀恐怖展姐,靈堂內(nèi)的尸體忽然破棺而出躁垛,到底是詐尸還是另有隱情,我是刑警寧澤圾笨,帶...
    沈念sama閱讀 36,185評論 5 350
  • 正文 年R本政府宣布缤苫,位于F島的核電站,受9級特大地震影響墅拭,放射性物質(zhì)發(fā)生泄漏活玲。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,870評論 3 333
  • 文/蒙蒙 一谍婉、第九天 我趴在偏房一處隱蔽的房頂上張望舒憾。 院中可真熱鬧,春花似錦穗熬、人聲如沸镀迂。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,340評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽探遵。三九已至,卻和暖如春妓柜,著一層夾襖步出監(jiān)牢的瞬間箱季,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,460評論 1 272
  • 我被黑心中介騙來泰國打工棍掐, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留藏雏,地道東北人。 一個月前我還...
    沈念sama閱讀 48,909評論 3 376
  • 正文 我出身青樓作煌,卻偏偏與公主長得像掘殴,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子粟誓,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,512評論 2 359

推薦閱讀更多精彩內(nèi)容