Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role for htpasswd-from-dict #398

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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