Skip to content

Commit

Permalink
Add role for htpasswd-from-dict (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
pabrahamsson authored and tylerauerbeck committed Nov 11, 2019
1 parent f903178 commit be59970
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
45 changes: 45 additions & 0 deletions roles/identity-management/htpasswd-from-dict/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
htpasswd-from-dict
==================

Create a htpasswd file based on a dictionary list

Requirements
------------

This module will require passlib to be installed

Role Variables
--------------

| Name | Description | Default | Required |
| ---- | ----------- | ------- | -------- |
| htpasswd_output_path | Where to write the htpasswd file | /tmp/htpasswd | no |
| htpasswd_users | List of usernames & passwords| [] | no |

Example Playbook
----------------

Including an example of how to use your role
```
---
- hosts: localhost
roles:
- identity-management/htpasswd-from-dict
vars:
htpasswd_output_path: /var/www/htpasswd
htpasswd_users:
- username: user1
password: password1
- username: user2
password: password2
```

License
-------

Apache License 2.0

Author Information
------------------

Red Hat Community of Practice & staff of the Red Hat Open Innovation Labs.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
htpasswd_output_path: /tmp/htpasswd
htpasswd_users: []

# htpasswd_users:
# - username: user1
# password: password1
# - username: user2
# password: password2
17 changes: 17 additions & 0 deletions roles/identity-management/htpasswd-from-dict/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Ensure {{ htpasswd_output_path | dirname }} exist
file:
path: "{{ htpasswd_output_path | dirname }}"
state: directory

- name: Delete old htpasswd file (if it exist)
file:
path: "{{ htpasswd_output_path }}"
state: absent

- name: Create htpasswd file
htpasswd:
path: "{{ htpasswd_output_path }}"
name: "{{ item.username }}"
password: "{{ item.password }}"
loop: "{{ htpasswd_users }}"
2 changes: 2 additions & 0 deletions roles/identity-management/htpasswd-from-dict/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

1 change: 1 addition & 0 deletions roles/identity-management/htpasswd-from-dict/tests/roles
12 changes: 12 additions & 0 deletions roles/identity-management/htpasswd-from-dict/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- hosts: localhost
remote_user: root
roles:
- identity-management/htpasswd-from-dict
vars:
htpasswd_users:
- username: user1
password: password1
- username: user2
password: password2
htpasswd_output_path: /tmp/ansible-test/htpasswd

0 comments on commit be59970

Please sign in to comment.