geerlingguy.htpasswd

Ansible 角色:htpasswd

CI

这是一个 Ansible 角色,用于安装 htpasswd 并轻松配置 htpasswd 认证文件和凭据(用于与 Apache 和 Nginx 等 web 服务器的 HTTP 基本认证)在基于 Linux 的服务器上。

需求

无。

角色变量

可用的变量如下所示,以及默认值(请参见 defaults/main.yml):

htpasswd_nolog: true

是否在 Ansible 的日志输出中显示 htpasswd 凭据。除非你在调试,否则应保持为 true

htpasswd_credentials:
  - path: /etc/nginx/passwdfile
    name: johndoe
    password: 'supersecure'
    owner: root
    group: www-data
    mode: 'u+rw,g+r'

  - path: /etc/apache2/passwdfile
    name: janedoe
    password: 'supersecure'
    owner: root
    group: www-data
    mode: 'u+rw,g+r'

要在各个文件中生成(或删除)的凭据列表,每个字典的 path 键定义了文件路径。除了 mode,所有参数都是必需的(mode 默认为 'u+rw,g+r'(八进制的 0640))。

htpasswd_required_packages:
  - apache2-utils
  - python3-passlib

(显示的是 Debian 的默认值)。你可以使用此变量覆盖已安装的包(例如,对于 CentOS 7,可以将 python3-passlib 更改为 python-passlib)。

依赖

无。

示例剧本

Apache 示例

---
- hosts: apache-server

  vars:
    htpasswd_credentials:
      - path: /etc/apache-passwdfile
        name: johndoe
        password: 'supersecure'
        owner: root
        group: apache
        mode: 'u+rw,g+r'

    apache_remove_default_vhost: True
    apache_vhosts:
      - listen: "80"
        servername: "htpassword.test"
        documentroot: "/var/www/html"
        extra_parameters: |
              <Directory "/var/www/html">
                  AuthType Basic
                  AuthName "Apache with basic auth."
                  AuthUserFile /etc/apache-passwdfile
                  Require valid-user
              </Directory>

  pre_tasks:
    - name: 更新 apt 缓存。
      apt: update_cache=yes cache_valid_time=600
      when: ansible_os_family == 'Debian'

  roles:
    - geerlingguy.apache
    - geerlingguy.htpasswd

Nginx 示例

---
- hosts: nginx-server

  vars:
    htpasswd_credentials:
      - path: /etc/nginx/passwdfile
        name: johndoe
        password: 'supersecure'
        owner: root
        group: www-data
        mode: 'u+rw,g+r'

    nginx_remove_default_vhost: True
    nginx_vhosts:
      - listen: "80"
        server_name: "htpassword.test"
        root: "/var/www/html"
        index: "index.html index.html index.nginx-debian.html"
        filename: "htpassword.test.conf"
        extra_parameters: |
              location / {
                  auth_basic           "Nginx with basic auth.";
                  auth_basic_user_file /etc/nginx/passwdfile;
              }

  pre_tasks:
    - name: 更新 apt 缓存。
      apt: update_cache=yes cache_valid_time=600
      when: ansible_os_family == 'Debian'

  roles:
    - geerlingguy.nginx
    - geerlingguy.htpasswd

许可证

MIT / BSD

作者信息

此角色由 Jeff Geerling 于2018年创建,他是 Ansible for DevOps 的作者。

安装
ansible-galaxy install geerlingguy.htpasswd
许可证
mit
下载
139.6k
拥有者
Father, author, developer, maker. Sometimes called "an inflammatory enigma". #stl #drupal #ansible #k8s #raspberrypi #crohns