http://en.wikipedia.org/wiki/Comparisonofopen-source_configurationmanagementsoftware
上边链接汇总了相关开源工具,我用了一整天时间几乎把所有的工具都尝试了一遍,经过方方面面的对比,最终选择了老牌unix运维工具:Ansible
这里重点说一下如何使用ansible
sudo apt-get install software-properties-common sudo apt-add-repository ppa:ansible/ansible sudo apt-get update sudo apt-get install ansible
测试是否安装成功
<pre name="code" class="plain">ansible --version echo "[192.168.99.81] ansible_ssh_port=[22] ansible_ssh_user=[username] ansible_ssh_private_key_file=/path/to/pem/file | sudo tee > /etc/ansible/hosts ansible 192.168.99.81 -m command -a 'whoami'
注意上述[]表示这部分是需要替换的变量,实际是不存在[]的
sudo vim /etc/ansible/ansible.cfg gathering = explicit host_key_checking = False record_host_keys = False scp_if_ssh = True ssh_args = -o PreferredAuthentications=publickey
总让ansible去一条条执行命令太low,真正用的时候还是要玩儿playbook. 所谓playbook就是说我想做一件事情,分成若干个task;每步执行失败或者重试、或者终止,简单的不得了。
还是拿升级来举例:
创建一个hosts文件
echo "192.168.99.83 ansible_ssh_port=22 ansible_ssh_user=devops ansible_ssh_private_key_file=/path/to/pem/file" > /tmp/__hosts.txt~IFYNaj
创建一个文件叫做upgrade.yml
--- - hosts: "{{host}}" remote_user: devops sudo: no gather_facts: False tasks: - name: 1. UPLOAD copy: src={{ item.src }} dest={{ item.dest }} mode=0775 with_items: - {src: "upgrade.sh", dest: "/home/devops/"} - {src: "/home/devops/upload/bin/{{pkg}}", dest: "/home/devops/"} - name: 2. UPGRADE shell: /home/devops/upgrade.sh {{pkg}}
调用:
ansible-playbook action/upgrade.yml --extra-vars 'host=all pkg=hello.exe' -i /tmp/__host.txt~IFYNaj
- name: 1. UPLOAD copy: src={{ item.src }} dest={{ item.dest }} mode=0775 with_items: - {src: "upgrade.sh", dest: "/home/devops/"} - {src: "/home/devops/upload/bin/{{pkg}}", dest: "/home/devops/"}
这是playbook的变量,表示可以从外部传入的参数。这样可以让做差不多事情的playbook重复使用。参数真正的值由调用时通过--extra-vars
传入
如果你的脚本成功时候也不返回0,那么请参阅手册怎么处理 :-(
原文地址:http://blog.csdn.net/sunyurun/article/details/43463915