diff --git a/roles/identity-management/htpasswd-from-dict/README.md b/roles/identity-management/htpasswd-from-dict/README.md new file mode 100644 index 000000000..1b7d13733 --- /dev/null +++ b/roles/identity-management/htpasswd-from-dict/README.md @@ -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. diff --git a/roles/identity-management/htpasswd-from-dict/defaults/main.yml b/roles/identity-management/htpasswd-from-dict/defaults/main.yml new file mode 100644 index 000000000..a212d5d67 --- /dev/null +++ b/roles/identity-management/htpasswd-from-dict/defaults/main.yml @@ -0,0 +1,9 @@ +--- +htpasswd_output_path: /tmp/htpasswd +htpasswd_users: [] + +# htpasswd_users: +# - username: user1 +# password: password1 +# - username: user2 +# password: password2 diff --git a/roles/identity-management/htpasswd-from-dict/tasks/main.yml b/roles/identity-management/htpasswd-from-dict/tasks/main.yml new file mode 100644 index 000000000..09fee10d2 --- /dev/null +++ b/roles/identity-management/htpasswd-from-dict/tasks/main.yml @@ -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 }}" diff --git a/roles/identity-management/htpasswd-from-dict/tests/inventory b/roles/identity-management/htpasswd-from-dict/tests/inventory new file mode 100644 index 000000000..878877b07 --- /dev/null +++ b/roles/identity-management/htpasswd-from-dict/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/identity-management/htpasswd-from-dict/tests/roles b/roles/identity-management/htpasswd-from-dict/tests/roles new file mode 120000 index 000000000..4bdbcbad3 --- /dev/null +++ b/roles/identity-management/htpasswd-from-dict/tests/roles @@ -0,0 +1 @@ +../../../../roles \ No newline at end of file diff --git a/roles/identity-management/htpasswd-from-dict/tests/test.yml b/roles/identity-management/htpasswd-from-dict/tests/test.yml new file mode 100644 index 000000000..6251ba109 --- /dev/null +++ b/roles/identity-management/htpasswd-from-dict/tests/test.yml @@ -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