//命令示例 yum模塊
# ansible localhost-vm -m yum -a 'name=httpd,memcached state=installed update_cache=yes'
yum //模塊名
name //後接需要安裝的包名,多個時用 , 隔開。也可接本地rpm路徑,安裝本地包(如name=/root/src/popt-static-1.13-7.el6.x86_64.rpm)
state //state有多種狀態('present' or 'installed', 'latest' 或 'absent' or 'removed')
update_cache //更新緩存(可忽略)
//卸載包
# ansible localhost-vm -m yum -a 'name=httpd,memcached state=absent'
//命令示例 service模塊
# ansible localhost-vm -m service -a 'name=rpcbind state=started enabled=yes'service //模塊名稱
name //後接服務名稱
state //後接操作(包含 {started | stopped | restarted | reloaded})enable //是否開機啓用(可忽略)(yes or no 或 true or false)# ansible localhost-vm -m shell -a 'ps aux|grep rpcbind' //檢查
//命令示例 user模塊
# ansible localhost-vm -m user -a 'name=nginx shell=/sbin/nologin system=yes groups=root group=nginx home=/home/nginx comment="nginx service"'
user //模塊名
name //指定用戶名
shell //指定使用的shell
system //是否是系統用戶(可忽略)groups //指定附屬組
group //指定主組
home //指定家目錄(可忽略)
comment //註釋(可忽略)
//需要注意:主組、附屬組、家目錄等如果不存在需要先創建
//更多參數,詳見 # ansible-doc user
//刪除用戶
# ansible localhost-vm -m user -a 'name=nginx shell=/sbin/nologin system=yes groups=root comment="nginx service" state=absent'
//檢查
# ansible localhost-vm -m shell -a 'id nginx'
//命令示例 group模塊
# ansible localhost-vm -m group -a 'name=nginx system=yes'
group //模塊名
name //指定組名稱
system //是否是系統組(可忽略)
//更多參數,詳見 # ansible-doc group
//刪除組
# ansible localhost-vm -m group -a 'name=nginx system=yes state=absent'
//檢查
# ansible localhost-vm -m shell -a 'getent group nginx'