ansible命令
ansible ansible-galaxy ansible-pull ansible-vault
ansible-doc ansible-playbook ansible-shell
# ansible-doc -l 查看modules
# ansible-doc ping 查看ping模块的使用方法
> PING
A trivial test module, this module always returns `pong' on
successful contact. It does not make sense in playbooks, but it is
useful from `/usr/bin/ansible'
# Test 'webservers' status
#测试
1
2
3
4
5
6
7
8
[iyunv@manager ~]# ansible web1 -m ping
[WARNING]: The version of gmp you have installed has a known issue regarding
timing vulnerabilities when used with pycrypto. If possible, you should update
it (i.e. yum update gmp).
192.168.10.2 | success >> {
"changed": false,
"ping": "pong"
}
#下面开始
cd /etc/ansible/
vim hosts #注释所有,添加以下
[web1]
192.168.10.2
[web2]
192.168.10.3
#测试几个常用的命令
ansible web1 -a uptime
ansible web1 -m yum -a "name=dstat state=latest"
ansible web1 -m raw -a "rpm -qa|grep dstat"
ansible web1 -m shell -a "service mysqld restart"
ansible web1 -m service -a "name=mysqld state=stopped"