ansible
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAnsible
Ansible
Ansible is an agentless automation tool. It handles Configuration Management (installing Nginx, editing configs). 2025 sees the Automation Platform 2.5 unified UI and AI Lightspeed assistance.
Ansible是一款无代理自动化工具,可用于配置管理(如安装Nginx、编辑配置文件)。2025年推出的Automation Platform 2.5具备统一UI和AI Lightspeed辅助功能。
When to Use
适用场景
- Configuration Mgmt: Terraform creates the VM, Ansible installs the software inside it.
- Agentless: No software to install on targets. Needs only SSH.
- Network Automation: Configuring Routers/Switches.
- 配置管理:Terraform创建虚拟机后,Ansible负责在内部安装软件。
- 无代理架构:无需在目标主机上安装软件,仅需SSH即可。
- 网络自动化:配置路由器/交换机。
Quick Start
快速开始
yaml
undefinedyaml
undefinedplaybook.yml
playbook.yml
- name: Configure Webservers
hosts: web
become: true
tasks:
-
name: Install Nginx ansible.builtin.apt: name: nginx state: present
-
name: Start Service ansible.builtin.service: name: nginx state: started
-
undefined- name: Configure Webservers
hosts: web
become: true
tasks:
-
name: Install Nginx ansible.builtin.apt: name: nginx state: present
-
name: Start Service ansible.builtin.service: name: nginx state: started
-
undefinedCore Concepts
核心概念
Inventory
清单(Inventory)
List of hosts ( or YAML). Can be dynamic (AWS plugin).
hosts.ini主机列表(存储为或YAML格式),支持动态清单(如AWS插件)。
hosts.iniPlaybooks
Playbook
YAML files defining the desired state.
定义期望状态的YAML文件。
Roles / Collections
角色/集合(Roles / Collections)
Reusable units of code. Download from Ansible Galaxy.
可复用的代码单元,可从Ansible Galaxy下载。
Best Practices (2025)
2025年最佳实践
Do:
- Use Collections: The modern packaging format. is better than short modules.
ansible.builtin - Use : Enforce best practices.
ansible-lint - Idempotency: Ensure running a playbook twice produces the same result without errors.
Don't:
- Don't use module: Unless absolutely necessary. Use specific modules (
shell,user,file) for key tasks.apt
建议:
- 使用集合:采用现代化的打包格式,优先使用而非短模块。
ansible.builtin - 使用:强制遵循最佳实践。
ansible-lint - 幂等性:确保重复运行Playbook两次能得到相同结果且无错误。
不建议:
- 避免使用模块:除非绝对必要,核心任务应使用专用模块(如
shell、user、file)。apt