ansible ad-hoc 参考
# 检查主机连接 # ansible test -m ping
# 执行远程命令 # ansible test -m command -a 'uptime'
# 执行主控端脚本 # ansible test -m script -a '/etc/ansible/script/test.sh'
# 执行远程主机的脚本 # ansible test -m shell -a 'ps aux|grep zabbix'
# 类似shell # ansible test -m raw -a "ps aux|grep zabbix|awk '{print \$2}'"
# 创建软链接 # ansible test -m file -a "src=/etc/resolv.conf dest=/tmp/resolv.conf state=link"
# 删除软链接 # ansible test -m file -a "path=/tmp/resolv.conf state=absent"
# 复制文件到远程服务器 # ansible test -m copy -a "src=/etc/ansible/ansible.cfg dest=/tmp/ansible.cfg owner=root group=root mode=0644"
# 指定主机 #ansible -i /etc/ansible/hosts all -m copy -a "src=test.conf dest=/etc/test.conf owner=root group=root mode=0644"
#确保一个包已经安装,但是不进行update操作 #ansible webservers -m yum -a "name=acme state=installed"
#查看已经安装了指定版本的软件包 #ansible webservers -m yum -a "name=acme-1.5 state=installed"
#查看安装软件包是否为最新版本 #ansible webservers -m yum -a "name=acme state=latest"
#确保一个软件包是没有安装的 #ansible webservers -m yum -a “name=acme state=removed"
#'user'模块可以方便的创建或者操作一个用户帐号,同样的也可以删除一个用户 #ansible all -m user -a "name=test password=<abc>" #ansible all -m user -a "name=test state=absent"
#确定服务都是开启的 #ansible all -m service -a "name=httpd state=started" #重启服务 #ansibel all -m service -a "name=httpd state=restarted" #关闭服务 #ansible all -m service -a "name=httpd state=stoped"
#get_url从服务器上下载一个文件到远程主机指定的目录 #ansible webservers -m get_url -a "url='http://baidu.com dest=/tmp/ba.html" #setup收集远程服务器信息 #ansible all -m setup