概述
- Ansible 是一款开源 IT 自动化工具,能够自动执行置备、配置管理、应用部署、编排和许多其他手动 IT 流程。与更为简易的管理工具不同,Ansible 用户(如系统管理员、开发人员和架构师)可以运用 Ansible 自动化,在整个企业范围内更高效地安装软件、自动执行日常任务、置备基础架构、提高安全性和合规性、修补系统并共享自动化
特点
- 部署简单,只需在主控端部署 Ansible 环境,被控端无需做任何操作;
- 默认使用SSH协议对设备进行管理;
- 有大量常规运维操作模块,可实现日常绝大部分操作;
- 配置简单、功能强大、扩展性强;
- 支持API及自定义模块,可通过Python轻松扩展;
- 通过Playbooks来定制强大的配置、状态管理;
- 轻量级,无需在客户端安装agent,更新时,只需在操作机上进行一次更新即可;
- 提供一个功能强大、操作性强的Web管理界面和REST API接口——AWX平台。
安装部署
yum install -y ansible
注意:通过yum安装需要优化epel源
命令
ansible
说明:针对一组主机定义并运行单个任务
ansible-doc
说明:插件文档工具
命令常用参数详细说明
参数 | 说明 |
-l, –list | List available plugins – 列出可以的插件(模块) |
-s, –snippet | Show playbook snippet for specified plugin(s) – 显示指定插件的剧本片段,简单输出 |
Demo
[root@m01 ~] $ ansible-doc -l|wc -l
3387
[root@m01 ~] $ ansible-doc -s ping
- name: Try to connect to host, verify a usable python and return `pong' on success
ping:
data: # Data to return for the `ping' return value. If this parameter is set to `crash', the module will cause an exception.
模块 modules
ping
概述
英文说明 | 翻译 |
A trivial test module, this module always returns pong' on successful contact. It does not make sense in playbooks, but it is useful from /usr/bin/ansible’ to verify the ability to login and that a usable Python is configured. Thisis NOT ICMP ping, this is just a trivial test module that requires Python on the remote-node. For Windows targets, use the [win_ping] module instead. For Network targets, use the [net_ping] module instead. | 作为一个微不足道的测试模块,该模块在成功接触时总是返回“pong”。这在剧本中没有意义, 但从“/usr/bin/ansible”中验证登录能力以及是否配置了可用的Python是很有用的。这 不是ICMP ping,这只是一个简单的测试模块,需要在远程节点上使用Python。对于Windows目标, 请改用[win_ping]模块。对于网络目标,请改用[net_ping]模块。 |
基本使用
[root@m01 ~] $ ansible 172.16.1.11 -m ping
172.16.1.11 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}