ansible.builtin vs ansible.posix 核心对比

一、基础属性对比

| 维度 | ansible.builtin | ansible.posix |

| 归属 | Ansible 核心内置模块集(ansible-core)| Ansible 官方维护的 POSIX 专属集合 |

| 安装方式 | 随 ansible-core 预装,无需额外安装 | 需手动安装:`ansible-galaxy collection install ansible.posix` |

| 适用范围 | 跨平台(Linux/Windows/BSD 等)| 仅 POSIX 系统(Linux/Unix 类)|

| 核心定位 | 通用、基础、跨平台模块 | Linux 系统级、精细化管理模块 |

| 调用方式 | 可省略前缀(如 `command:` 等效 `ansible.builtin.command:`) | 必须写全前缀(如 `ansible.posix.acl:`) |

二、核心模块对比

✅ ansible.builtin(通用基础模块) 覆盖所有场景的"基础款",无需额外依赖:

| 模块类型 | 代表模块 | 用途 |

| 命令执行 | command、shell | 执行远程命令 |

| 文件管理 | file、copy、template | 管理文件/目录/配置 |

| 包管理 | yum、apt、dnf | 安装软件包 |

| 服务管理 | service、systemd | 管理系统服务 |

| 变量/调试 | debug、set_fact | 调试、定义变量 |

| 条件/流程 | when、block/rescue | 控制执行流程 |

| 定时任务 | cron | 管理 crontab 任务 |

✅ ansible.posix(Linux 专属增强模块) 补充 `builtin` 未覆盖的 Linux 系统级能力,更精细化:

| 模块类型 | 代表模块 | 用途 |

| 权限精细化 | acl | 管理文件 ACL 权限 |

| SSH 管理 | authorized_key | 配置 SSH 免密登录 |

| 系统调优 | sysctl | 管理内核参数 |

| 挂载管理 | mount | 管理文件系统挂载 |

| 防火墙 | firewalld | 管理 firewalld 规则 |

| 文件同步 | synchronize | 基于 rsync 同步文件 |

| SELinux 管理 | seboolean、selinux | 管理 SELinux 策略 |

三、核心使用原则

  1. 优先用 ansible.builtin - 场景:通用操作(如 copy 文件、启动服务、安装软件);
  • 优势:无需额外安装、跨平台、稳定性高;
  1. 需精细化 Linux 操作时用 ansible.posix - 场景:Linux 系统级精细化管理(如 ACL 权限、SSH 公钥、内核参数); - 前提:先安装集合 `ansible-galaxy collection install ansible.posix`; - 示例:

四、关键注意事项

  1. 调用前缀: - `ansible.builtin` 可省略(如 `command:` 等效 `ansible.builtin.command:`); - `ansible.posix` 必须写全前缀(不能只写 `acl:`,必须写 `ansible.posix.acl:`)。

  2. 依赖差异: - `builtin` 模块无额外依赖(Ansible 自带); - `posix` 模块可能依赖目标主机的系统工具(如 `acl` 模块依赖 `setfacl` 命令)。

  3. 版本兼容: - `builtin` 随 ansible-core 版本更新,兼容性强; - `posix` 需单独升级(`ansible-galaxy collection install ansible.posix --upgrade`)。

总结

  1. ansible.builtin:Ansible 核心"通用工具箱",预装、跨平台、覆盖基础操作;

  2. ansible.posix:Linux 专属"增强工具箱",需手动装、仅适用于 POSIX 系统、做精细化管理;

  3. 核心选择逻辑:通用操作用 `builtin`,Linux 系统级精细化操作(ACL/SELinu/rsync 等)用 `posix`。 简单记:`builtin` = 基础通用,`posix` = Linux 专属增强。

相关推荐
炸炸鱼.1 天前
Ansible 部署应用:从入门到精通
ansible
Peace1 天前
【Ansible】
linux·运维·ansible
Plastic garden2 天前
K8s(1)前置ansible准备环境
容器·kubernetes·ansible
遇见火星4 天前
从0到1掌握Ansible:让自动化运维不再是梦想
运维·自动化·ansible
遇见火星4 天前
Jenkins + Ansible 集成实战:把配置管理焊进流水线里
运维·ansible·jenkins
江华森6 天前
Ansible 自动化运维:从入门到实战
运维·自动化·ansible
JackSparrow4147 天前
使用Ansible批量管理+更新产品环境服务器配置
运维·服务器·ci/cd·kubernetes·自动化·ansible·sre
Cat_Rocky10 天前
Linux-ansible之Playbook简单应用
linux·网络·ansible
淼淼爱喝水11 天前
Ansible 入门实战:四种变量优先级比较实验
ansible·变量
淼淼爱喝水11 天前
ansible实战:「磁盘空间 ≥ 2G 时自动创建文件」
前端·ansible·自动创建