Ansible: 安装
2025-02-17
安装要求
控制节点要求
- Python 2.7 或 Python 3.5+
- SSH 客户端
- 不需要数据库
- 不需要后台进程
被管理节点要求
- Python
- SSH 服务
- SFTP 或 SCP
- 低版本 Python 需要 python-simplejson
安装方法
1. YUM 安装
# 添加 EPEL 源
yum -y install epel-release
# 安装 Ansible
yum -y install ansible2. 源码安装
# 克隆源码
git clone git://github.com/ansible/ansible.git
cd ./ansible
# 安装依赖
yum install -y rpm-build make python2-devel
# 构建 RPM 包
make rpm
# 安装
rpm -Uvh ~/rpmbuild/ansible-*.noarch.rpm3. PIP 安装
# 安装 pip
easy_install pip
# 安装 Ansible
pip install ansible验证安装
# 检查版本
ansible --version
# 测试连接
ansible localhost -m ping配置文件
# 创建配置目录
mkdir -p /etc/ansible
# 创建配置文件
cat > /etc/ansible/ansible.cfg <<EOF
[defaults]
inventory = /etc/ansible/hosts
remote_user = root
host_key_checking = False
EOF最佳实践
安装建议
- 使用包管理器安装
- 选择稳定版本
- 统一安装方式
配置建议
- 使用独立配置文件
- 设置合适的权限
- 保持版本一致
注意:
- 确保 Python 版本兼容
- 检查系统依赖
- 注意网络连通性
参考资料: