1. 程式人生 > 實用技巧 >Ansible 的 ad-hoc

Ansible 的 ad-hoc

1.什麼是ad-hoc

ad-hoc簡而言之就是遠端執行“臨時命令”,執行完即結束,並不會儲存

2.ad-hoc使用場景

比如在多臺機器上檢視某個程序是否啟動,或拷貝指定檔案到本地,等等

3.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

4.ad-hoc返回結果顏色含義

綠色: 代表被管理端主機沒有被修改
黃色: 代表被管理端主機發現變更
紅色: 代表出現了故障,注意檢視提示
紫色:警告

5.ad-hoc常用模組

command             # 執行shell命令(不支援管道等特殊字元)
shell               # 執行shell命令
script              # 執行shell指令碼
yum_repository      # 配置yum倉庫
yum                 # 安裝軟體
copy                # 變更配置檔案
file                # 建立目錄或檔案
service             # 啟動與停止服務
mount               # 掛載裝置
cron                # 定時任務
get_url             # 下載軟體
firewalld           # 防火牆
selinux             # selinux

6.ad-hoc幫助

#檢視所有模組
[root@m01 ~]# ansible-doc -l

#常看指定模組使用方法
[root@m01 ~]# ansible-doc command
EXAMPLES:

#檢視模組可以使用的引數
[root@m01 ~]# ansible-doc -s file