ansible配置shell
说明:关于ansible hosts文件中可用参数:bash
ansible_ssh_port=22 #远程主机登录端口ssh
ansible_ssh_user=root #远程主机登录用户名ide
ansible_ssh_pass=chekir #远程主机登录用户名的密码测试
ansible_ssh_private_key_file=/etc/ansible/hosts #指定管理主机群列表文件spa
host_key_checking=False #跳过第一次链接检测询问是否登录的提示(YES/NO)orm
这里hosts文件我作了互信认证,因此hosts文件我就写了个主机IP,端口号默认的话能够不用写it
一、备份ansible hosts文件:class
[root@soso ~]# cp /etc/ansible/hosts /etc/ansible/hosts.bak
二、清空hosts文件,定义主机分组test
[root@soso ~]# cat /etc/ansible/hosts [test] 192.168.1.2
三、测试ansible
[root@soso ~]# ansible -i /etc/ansible/hosts test -m shell -a 'uptime' 192.168.1.2 | success | rc=0 >> 14:28:04 up 21:12, 3 users, load average: 0.01, 0.02, 0.00 [root@soso ~]# ansible test -i /etc/ansible/hosts -m command -a 'date' 192.168.1.2 | success | rc=0 >> Wed Dec 16 14:30:40 CST 2015
#参数解释:
-i: 指定主机列表文件
-u: 指定远程主机登录用户
-m:指定使用ansible 的模块
-a: 指定模块下使用的参数
-k: 指定远程登录用户的密码
上面测试的命令还能够简写:
[root@soso ~]# ansible test -a 'date' 192.168.1.2 | success | rc=0 >> Wed Dec 16 14:33:53 CST 2015
测试远程主机状态,查看是否存活
[root@soso ~]# ansible all -m ping 192.168.1.2 | success >> { "changed": false, "ping": "pong" }