安装ansible
[root@centos01 ~]# yum -y install ansible
配置ansbile客户端
[root@centos01 ~]# vim /etc/ansible/hosts
[web]
192.168.100.20
192.168.100.30
测试客户端的连通性
客户端配置文件列表测试
[root@centos01 ~]# ansible -i /etc/ansible/hosts web -m ping
加载ping模块测试
[root@centos01 ~]# ansible web -m ping
ansible交互式管理
使用ansible交互式工具
[root@centos01 ~]# ansible-console
切换组
root@all (2)[f:5]$ cd web
列出客户端
root@web (2)[f:5]$ list
使用shell模块查看sshd服务状态
[root@centos01 ~]# ansible web -m shell -a ‘netstat -anptu | grep sshd’
重定向操作
[root@centos01 ~]# ansible web -m shell -a ‘echo “centos02 192.168.100.20” etc/hosts’
远程切换目录
[root@centos01 ~]# ansible web -m command -a ‘chdir=/ ls ./’
应用copy
[root@centos01 ~]# ansible web -m copy -a ‘src=/etc/hosts dest=/root/host01 mode=777 owner=test group=root’
安装apache
[root@centos01 ~]# ansible web -m yum -a ‘name=httpd state=present’
管理apache服务
[root@centos01 ~]# ansible web -m service -a ‘name=httpd state=stopped’
创建用户
[root@centos01 ~]# ansible web -m user -a ‘name=bob system=yes shell=/bin/bash’