ansible是基於 Python paramiko 開發,分佈式,無需客戶端,輕量級,配置語法使用 YMAL 及 Jinja2模板語言,更強的遠程命令執行操做。linux
Ansible 在管理節點將 Ansible 模塊經過 SSH 協議(或者 Kerberos、LDAP)推送到被管理端執
行,執行完以後自動刪除,能夠使用 SVN 等來管理自定義模塊及編排。web
ansible提供上千個模塊,經常使用的模塊就一小部分列出經常使用模塊一些shell
#拷貝本地的/etc/hosts 文件到 atlanta 主機組全部主機的/tmp/hosts ansible atlanta -m copy -a "src=/etc/hosts dest=/tmp/hosts" #file 模塊容許更改文件的用戶及權限和建立文件 ansible webservers -m file -a "dest=/srv/foo/b.txt mode=600 owner=mdehaan group=mdehaan" ansible webservers -m file -a "dest=/path/to/c mode=755 owner=mdehaan group=mdehaan state=directory「 #service更改服務狀態 ansible webservers -m service -a "name=httpd state=started" #shell模塊遠程執行命令 ansible raleigh -m shell -a 'echo $TERM' #yum模塊rpm軟件包管理 ansible webservers -m yum -a "name=acme state=present" #user 模塊對於建立新用戶和更改、刪除已存在用戶 ansible all -m user -a "name=foo password=<crypted password here>" ansible all -m user -a "name=foo state=absent"
Playbooks 是 Ansible 管理配置、部署應用和編排的語言,能夠使用 Playbooks 來描述你想在遠
程主機執行的策略或者執行的一組步驟過程等apache
Playbooks 組成:windows
例子:架構
- hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running service: name=httpd state=started handlers: - name: restart apache service: name=httpd state=restarted