應用
在遠程主機上執行ansible主機上的腳本,且不需要將腳本復制到被執行的遠程主機上
參數
- 腳本路徑,必須參數
- chdir:在執行腳本之前,先進入到指定目錄
- creates:當遠程主機上的該文件存在時,不執行腳本;反之執行
- removes:當遠程主機上的該文件不存在時,不執行腳本;反之執行
示例
- 先進入/opt目錄下,再執行test.sh腳本
]# ansible all -m script -a 'chdir=/opt /opt/test.sh'
- 若/opt/a.file存在時,不執行test.sh腳本
]# ansible all -m script -a 'creates=/opt/a.file /opt/test.sh'
- 若/opt/a.file不存在時,不執行test.sh腳本
]# ansible all -m script -a 'removes=/opt/a.file /opt/test.sh'