weareinteractive.ufw

Ansible weareinteractive.ufw 角色

构建状态 Galaxy GitHub 标签 GitHub 星标

weareinteractive.ufw 是一个 Ansible 角色,它可以:

  • 安装 ufw
  • 配置 ufw
  • 配置 ufw 规则
  • 配置服务

安装

使用 ansible-galaxy:

$ ansible-galaxy install weareinteractive.ufw

使用 requirements.yml:

- src: weareinteractive.ufw

使用 git:

$ git clone https://github.com/weareinteractive/ansible-ufw.git weareinteractive.ufw

依赖

  • Ansible >= 2.10

变量

以下是此角色的所有默认变量列表,这些变量也可在 defaults/main.yml 中找到。

---
# 启动服务并在系统启动时启用
ufw_enabled: true

# 要安装的包列表
ufw_packages: ["ufw"]

# 服务名称
ufw_service: ufw

# 应用的规则列表
# 请参阅 https://docs.ansible.com/ansible/latest/collections/community/general/ufw_module.html 获取文档
ufw_rules:
  - rule: allow
    to_port: 22

# 管理配置文件
ufw_manage_config: false

# 传递给配置文件的配置对象
ufw_config:
  IPV6: "yes"
  DEFAULT_INPUT_POLICY: DROP
  DEFAULT_OUTPUT_POLICY: ACCEPT
  DEFAULT_FORWARD_POLICY: DROP
  DEFAULT_APPLICATION_POLICY: SKIP
  MANAGE_BUILTINS: "no"
  IPT_SYSCTL: /etc/ufw/sysctl.conf
  IPT_MODULES: ""

# 配置文件的路径
ufw_config_file: /etc/default/ufw

处理程序

以下是定义在 handlers/main.yml 中的处理程序。

---

- name: 重置 ufw
  community.general.ufw:
    state: reset

- name: 重新加载 ufw
  community.general.ufw:
    state: reloaded
  when: ufw_enabled | bool

用法

以下是一个示例剧本:

# @see https://docs.ansible.com/ansible/latest/collections/community/general/ufw_module.html#examples
---

- hosts: all
  become: true
  roles:
    - weareinteractive.ufw
  vars:
    ufw_rules:
      # 设置日志
      - logging: "full"
      # 允许 OpenSSH
      - rule: allow
        name: OpenSSH
      # 删除 OpenSSH 规则
      - rule: allow
        name: OpenSSH
        delete: true
      # 允许所有访问 tcp 端口 80
      - rule: allow
        to_port: '80'
        proto: tcp
    # 管理配置文件
    ufw_manage_config: true
    # 传递给配置文件的配置对象
    ufw_config:
      IPV6: "yes"
      DEFAULT_INPUT_POLICY: DROP
      DEFAULT_OUTPUT_POLICY: ACCEPT
      DEFAULT_FORWARD_POLICY: DROP
      DEFAULT_APPLICATION_POLICY: SKIP
      MANAGE_BUILTINS: "no"
      IPT_SYSCTL: /etc/ufw/sysctl.conf
      IPT_MODULES: ""

测试

$ git clone https://github.com/weareinteractive/ansible-ufw.git
$ cd ansible-ufw
$ make test

贡献

在没有正式风格指南的情况下,请确保保持现有的编码风格。为任何新功能或更改的功能添加单元测试和示例。

  1. 分叉它
  2. 创建功能分支 (git checkout -b my-new-feature)
  3. 提交更改 (git commit -am '添加某些功能')
  4. 推送到分支 (git push origin my-new-feature)
  5. 创建新的 Pull Request

注意:如需更新 README.md 文件,请安装并运行 ansible-readme:

$ gem install ansible-readme
$ ansible-readme

许可证

版权所有 (c) We Are Interactive 采用 MIT 许可证。

关于项目

Installs and configures ufw

安装
ansible-galaxy install weareinteractive.ufw
许可证
mit
下载
240.4k