ansible
文档尚未完成,请勿转载!
版权 © 2008, 2009, 2010, 2011, 2012 Copyright Editor Groups, All Rights Reserved
版权声明
转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。
|
|
$Date: 2012-04-17 18:49:40 +0800 (Tue, 17 Apr 2012) $
下面是我多年积累下来的经验总结,整理成文档供大家参考:
1. ansible
http://ansible.github.com/
Ansible is a radically simple model-driven configuration management, deployment, and command execution framework.
Your first commands
/etc/ansible/hosts
# vim /etc/ansible/hosts 192.168.2.10 192.168.2.11 192.168.2.12 192.168.2.13 192.168.2.14 192.168.2.15
创建SSH公钥与私钥
ssh-keygen
将公钥文件复制到目标服务器
ssh-copy-id root@192.168.2.10 ssh-copy-id root@192.168.2.11 ssh-copy-id root@192.168.2.12 ssh-copy-id root@192.168.2.13 ssh-copy-id root@192.168.2.14 ssh-copy-id root@192.168.2.15
连接与验证测试 ansible all -m ping
# ansible all -m ping 192.168.2.10 | success >> { "module": "ping", "ping": "pong" } 192.168.2.13 | success >> { "module": "ping", "ping": "pong" } 192.168.2.14 | success >> { "module": "ping", "ping": "pong" } 192.168.2.11 | success >> { "module": "ping", "ping": "pong" } 192.168.2.15 | success >> { "module": "ping", "ping": "pong" } 192.168.2.12 | success >> { "module": "ping", "ping": "pong" }
1.3. ansible - run a command somewhere else
指定用户
# ansible all -m ping -u root
定义组
# cat /etc/ansible/hosts [www] 192.168.2.23
创建yml文件
# cat test.yml --- - hosts: www user: root tasks: - name: no selinux action: command /usr/sbin/setenforce 0 - name: no iptables action: service name=iptables state=stopped - name: made up task just to show variables work here action: command /bin/echo release is $release
执行任务
# ansible-playbook test.yml -u root -T 1 PLAY [www] ********************* GATHERING FACTS ********************* ok: [192.168.2.23] TASK: [no selinux] ********************* ok: [192.168.2.23] TASK: [no iptables] ********************* ok: [192.168.2.23] TASK: [made up task just to show variables work here] ********************* ok: [192.168.2.23] PLAY RECAP ********************* 192.168.2.23 : ok=4 changed=2 unreachable=0 failed=0