配置 hosts文件 vim /etc/ansible/hosts 将要使用ansible配置管理的机器添加到hosts文件:
[git] 192.168.1.106 [jenkins] 192.168.1.107 [nginx] 192.168.1.100 192.168.1.101 [all] 192.168.1.106 192.168.1.107192.168.1.100 保存退出! [root@ansible ~]# ansible all -m ping (测试所有主机能不能ping通) [root@ansible ~]# ansible git -a 'yum -y update' (-a 执行shell命令 git是hosts中定义的单个主机) [root@ansible ~]# ansible 192.168.1.107 -s -a 'date' (-s 参数-s告诉ansible使用sudo权限运行该命令) [root@ansible ~]# ansible git -m command -a 'cat /var/log/dmesg' (-m 指定模块 -a执行命令的传入 command是默认的模块,也已不写)