ansible模組之shell

ansible模組之shell

概要說明

ansible是一款非常強大的自動化運維工具,使我們可以很快捷地實現對遠端目標伺服器的自動化運維,包括伺服器維護,檔案操作,實時監控,專案服務更新,備份等等N多行為,就像你手工遠端到伺服器的一系列操作,都可以透過ansible幫你完成,而且它還是可以批次操作的。今天介紹的是它的shell模組。

1,在目標上執行shell命令

2,shell命令後可加多個引數,引數之間以空格隔開

3,它幾乎與ansible。builtin。command模組完全相同,但shell透過遠端節點上的(/bin/sh)執行命令

4,對於Windows目標,請改用ansible。Windows。win_shell模組

5,如果希望安全、可預測地執行命令,最好使用ansible。builtin。command模組

ansible模組之shell

引數說明

chdir

:在指定的目錄中執行shell命令

cmd:

要執行的命令,後跟可選引數

更多引數參見下圖:

ansible模組之shell

例項說明

下面這個例子,是在/mnt/test/exam目錄上執行build。sh,並輸入日誌到build。log中。

- name: build server

shell: 。/build。sh >>build。log

args:

chdir: /mnt/test/exam

下面的例子,是將檔案進行考貝

- name: copy build log

shell: cp -f /test/exam/build。log /root/exam/build。log