ient主机生效:
# ansible -a "df -h" --limit "client"
执行一个耗时任务:(-B 3600表示最多运行60分钟,-P 60表示每隔60s获取一次状态)
ansible all -B 3600 -P 60 -a "/usr/bin/long_running-operation --do-stuff"
其他ansible参数可使用ansible -h查看。
3> 常用模块命令举例
①file模块
创建文件符链接:
# ansible local -m file -a "src=/etc/resolv.conf dest=/tmp/resolv.conf state=link"
更改文件权限为755,属组为root:root:
ansible local -m file -a "dest=/tmp/resolv.conf mode=755 owner=root group=root"
②service模块
启动NTP服务:
# ansible local -m service -a "name=ntpd state=started enabled=yes"
③copy模块
将本地文件拷贝到远程服务器:
# ansible local -m copy -a "src=/etc/ansible/ansible.cfg dest=/tmp/ansible.cfg owner=root group=root mode=0644"
更多模块请参考命令ansible-doc -l
模块官网 http://docs.ansible.com/ansible/latest/list_of_all_modules.html