Ansible 的 ad-hoc
阿新 • • 發佈:2020-10-07
ad-hoc簡而言之就是遠端執行“臨時命令”,執行完即結束,並不會儲存
比如在多臺機器上檢視某個程序是否啟動,或拷貝指定檔案到本地,等等
[root@m01 ~]# ansible 'web01' -m shell -a 'free -m'
web01 | CHANGED | rc=0 >>
total used free shared buff/cache available
Mem: 972 110 461 19 400 667
Swap: 2047 0 2047
綠色: 代表被管理端主機沒有被修改
黃色: 代表被管理端主機發現變更
紅色: 代表出現了故障,注意檢視提示
紫色:警告
command # 執行shell命令(不支援管道等特殊字元) shell # 執行shell命令 script # 執行shell指令碼 yum_repository # 配置yum倉庫 yum # 安裝軟體 copy # 變更配置檔案 file # 建立目錄或檔案 service # 啟動與停止服務 mount # 掛載裝置 cron # 定時任務 get_url # 下載軟體 firewalld # 防火牆 selinux # selinux
#檢視所有模組
[root@m01 ~]# ansible-doc -l
#常看指定模組使用方法
[root@m01 ~]# ansible-doc command
EXAMPLES:
#檢視模組可以使用的引數
[root@m01 ~]# ansible-doc -s file