寫法如下:
[root@localhost ~]$ ansible 192.168.119.134 -m command -a 'date' # 對指定的主機遠程執行命令,-m 指定使用哪個模塊,-a 指定執行哪些命令 [root@localhost ~]$ ansible test -m command -a 'date' # 對指定的主機組遠程執行命令,需要先配置/etc/ansible/hosts [root@localhost ~]$ ansible 192.168.119.134 -m shell -a 'ls | grep txt' # 如果要執行的命令帶有管道,必須使用 shell 模塊