开始使用¶
ansible-hardening 角色可以与 OpenStack-Ansible 项目一起使用,也可以作为独立角色,与其他的 Ansible playbook 一起使用。本文档假定读者已经完成了 Ansible 安装指南 中的步骤。
安装 ansible-hardening 角色¶
ansible-hardening 角色的推荐安装方法是 ansible-galaxy (推荐) 或 git。
使用 ansible-galaxy¶
最简单的安装方法是使用 Ansible 安装提供的 ansible-galaxy 命令
ansible-galaxy install git+https://github.com/openstack/ansible-hardening
该 ansible-galaxy 命令会将角色安装到 /etc/ansible/roles/ansible-hardening,这使得它易于与 Ansible playbook 一起使用。
使用 git¶
首先,将角色克隆到您选择的目录
mkdir -p ~/.ansible/roles/
git clone https://github.com/openstack/ansible-hardening ~/.ansible/roles/ansible-hardening
Ansible 默认在 ~/.ansible/roles 中查找角色。
如果角色克隆到不同的目录,则必须在 ansible.cfg 文件中使用 roles_path 选项提供该目录。以下是使用自定义角色路径的 ansible.cfg 文件的示例
[DEFAULTS]
roles_path = /etc/ansible/roles:/home/myuser/custom/roles
使用此配置,Ansible 将在 /etc/ansible/roles 和 ~/custom/roles 中查找角色。
用法¶
ansible-hardening 角色与现有的 playbook 配合良好。以下是使用 ansible-hardening 角色的基本 playbook 的示例
---
- name: Harden all systems
hosts: all
become: yes
vars:
security_enable_firewalld: no
security_rhel7_initialize_aide: no
security_ntp_servers:
- 1.example.com
- 2.example.com
roles:
- ansible-hardening
在 vars 部分提供的变量可以启用、禁用或更改 ansible-hardening 角色中各种任务的配置。有关可用变量的更多详细信息,请参阅 强化域 (RHEL 7 STIG) 部分。
注意
该角色必须以 root 用户身份或具有 sudo 权限的用户身份运行。上面的示例使用 become 选项,该选项会在运行任务之前导致 Ansible 使用 sudo。如果该角色以 root 身份运行,则可以将此选项更改为 user: root。
警告
强烈建议首先以检查模式(通常称为 dry run)运行该角色,然后再进行任何修改。这使部署者有机会在将该角色应用于系统之前,查看所有建议的更改。使用 --check 参数与 ansible-playbook 一起使用,以使用检查模式。