AcidDemon/ansible-base-el

GitHub: AcidDemon/ansible-base-el

面向 Enterprise Linux 主机的 Ansible 基线角色,统一管理用户、软件包、系统参数和 nftables 防火墙配置。

Stars: 0 | Forks: 0

# ansible-base-el ![Ansible](https://img.shields.io/badge/Ansible-2.16%2B-EE0000?logo=ansible&logoColor=white) ![Enterprise Linux](https://img.shields.io/badge/EL-Alma%2FRocky%2FRHEL-0C7BDC) ![nftables](https://img.shields.io/badge/firewall-nftables-2496ED) [![License: MIT](https://img.shields.io/github/license/AcidDemon/ansible-base-el?color=blue)](LICENSE) [![Last commit](https://img.shields.io/github/last-commit/AcidDemon/ansible-base-el)](https://github.com/AcidDemon/ansible-base-el/commits/main) [![Repo size](https://img.shields.io/github/repo-size/AcidDemon/ansible-base-el)](https://github.com/AcidDemon/ansible-base-el) [![GitLab mirror](https://img.shields.io/badge/mirror-GitLab-FC6D26?logo=gitlab&logoColor=white)](https://git.inviziblenet.work/AcidDemon/ansible-base-el) 适用于 Alma/Rocky/RHEL 类主机的通用 Enterprise Linux 基线:基础 OS、 用户、软件包、sysctl、dnf-automatic,以及**单一所有者 nftables 防火墙**, 应用程序通过声明 `firewall_allow_tcp` / `firewall_trust_iifnames` / `firewall_forward_policy` 来进行扩展。base 永远不会引用应用程序,也永远不会 `flush` nftables。 ## 运行 ``` direnv allow # or: export ANSIBLE_CONFIG=$PWD/ansible.cfg ansible-galaxy collection install -r requirements.yml ansible-playbook -i inventory/hosts.yml site.yml ``` ## 本地 Vagrant 包含的 Vagrantfile 会启动一个地址为 `10.99.0.10` 的 AlmaLinux 9 虚拟机。该地址 与 `ansible-hardening-el` 的 vagrant inventory 匹配,因此你可以通过完整的 `base -> hardening` 链在同一台实时 主机上运行。 ``` vagrant up ansible-playbook -i inventory/vagrant.yml site.yml ``` Vagrantfile 还会创建一个静态的 `10.99.0.10/24` 接口。如果你要 指定 Vagrant 打印的 libvirt 管理地址,请覆盖主机 和管理 CIDR,以便防火墙保持该 SSH 路径开放: ``` ansible-playbook -i inventory/vagrant.yml site.yml \ -e ansible_host=192.168.121.21 \ -e '{"management_cidrs":["192.168.121.0/24"]}' ``` 要进行完整的链路测试,请在运行 base 之前生成 hardening 使用的 部署密钥,并使其公钥可供此 仓库访问: ``` ssh-keygen -t ed25519 -f ../ansible-hardening-el/files/ssh/deploy -N "" -C "ansible-deploy" cp ../ansible-hardening-el/files/ssh/deploy.pub files/ssh/deploy.pub ``` 然后从 `../ansible-hardening-el` 针对其 `inventory/vagrant.yml` 运行 hardening。 ## 防火墙契约 `management_cidrs`(管理员 SSH 来源),`firewall_allow_tcp`(公共 TCP), `firewall_allow_tcp_mgmt`(仅限管理的 TCP,默认 22),`firewall_trust_iifnames` (受信任的输入接口,例如 `podman*`),`firewall_forward_policy`。base 拥有 `inet base_filter`;fail2ban/crowdsec 拥有它们各自的表。 在 EL 系统上,当启用 nftables 防火墙时,此 role 默认会禁用 `firewalld`, 否则这两个工具会竞争相同的内核 nftables 规则集。只有在另一层刻意拥有该集成时, 才设置 `base_firewall_disable_firewalld: false`。
标签:Ansible, nftables, 系统提示词, 系统配置, 自动化运维, 防火墙