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