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 专属增强。

相关推荐
寂静or沉默1 天前
Ansible 学习总结
学习·ansible
袁煦丞 cpolar内网穿透实验室3 天前
ansible批量自动化清理服务器日志+远程管理!cpolar 内网穿透实验室第 710 个成功挑战
服务器·自动化·ansible·远程工作·内网穿透·cpolar
人间打气筒(Ada)4 天前
ansible之role角色
运维·ansible·自动化运维·template·role·红帽·批量部署
酷酷的崽7984 天前
Ansible解锁便捷运维新方式,内网 NAS 也能远程管
运维·服务器·ansible
WJ.Polar4 天前
Ansible Ad-Hoc命令
linux·运维·网络·ansible
zmjjdank1ng4 天前
如何保证ansible的幂等性
linux·服务器·ansible
梅孔立17 天前
Ansible 100 台服务器一键管控实战 进阶版
服务器·git·ansible
henry10101020 天前
Ansible自动化运维全攻略(AI生成)
linux·运维·python·ansible·devops
only_Klein23 天前
Ansible变量详解
运维·自动化·ansible