Ansible 支持对集群的小部分机器批量操作,然后逐步完成整个集群的操作。这对于需要机器重启的场景就非常实用。
Ansible 可以补充现有 Salt 和 puppet 系统的不足。比如重启那些运行在每个服务器上的 Agent 。
任务 Task
多个 Task 顺序执行,在每个 Task 执行结束可以通知 Hanlder 触发新操作。
变量 Variable
用户定义的变量。
环境 Facts
Facts 从每台服务器上收集得到,可以用作变量。
模块
比如 shell、ping、apt 等等
操作 Hanlder
修改 /etc/ansible/hosts 添加
[web] 192.168.1.2 192.168.1.3 192.168.1.4PS: 一般将 hosts 文件放到当前文件夹, 需要在命令中指定 hosts 文件位置
ansible -u root web -m ping -i ./hosts执行下 Helloworld:
ansible all -m ping -u root这样的入门教程已经完成了。
看其他几个常用的操作,体会一下,通过看命令你就会知道所做的操作,非常简单:
ansible -u root web -m copy -a "src=/etc/hosts dest=/tmp/hosts" ansible -u root web -m yum -a "name=abcd state=present" ansible -u root web -m yum -a "name=abcd state=absent" ansible -u root web -m user -a "name=foo password=" ansible -u root web -m user -a "name=foo state=absent ansible -u root web -m git -a "repo=git://blog.eood.cn/repo.git dest=/srv/myapp version=HEAD" ansible -u root web -m service -a "name=nginx state=started" ansible -u root web -m service -a "name=nginx state=restarted" ansible -u root web -m service -a "name=nginx state=stopped"
湘ICP备2022002427号-10 湘公网安备:43070202000427号
© 2013~2024 haote.com 好特网