Skip to content
This repository has been archived by the owner on Nov 2, 2022. It is now read-only.

Allow for changing user passwords #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 6 additions & 18 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
changed_when: false
tags: samba

# - name: "Installed Samba version:"
# debug:
# msg: "{{ samba_version }}"
# tags: samba

- name: Install SELinux package
package:
name: "{{ samba_selinux_packages }}"
Expand Down Expand Up @@ -146,16 +141,9 @@
with_items: "{{ samba_services }}"
tags: samba

- name: Create Samba users if they don't exist yet
shell: >
set -o nounset -o pipefail -o errexit &&
(pdbedit --user={{ item.name }} 2>&1 > /dev/null) \
|| (echo {{ item.password }}; echo {{ item.password }}) \
| smbpasswd -s -a {{ item.name }}
args:
executable: /bin/bash
with_items: "{{ samba_users }}"
no_log: true
register: create_user_output
changed_when: "'Added user' in create_user_output.stdout"
tags: samba
- include_tasks: users.yml
vars:
user: "{{ samba_user }}"
loop: "{{ samba_users }}"
loop_control:
loop_var: samba_user
64 changes: 64 additions & 0 deletions tasks/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
- block:
- name: Create tmpfile
tempfile:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be cleaner (and arguably more secure) to use tempfile for this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow? The tempfile module is being used here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I was looking at something else and got confused - you're right of course.

state: file
register: tmpfile
changed_when: false
tags:
- samba
- samba_user

- name: Ensure more secure file permissions
file:
path: "{{ tmpfile.path }}"
mode: "0600"
tags:
- samba
- samba_user

- name: Store password in tmpfile
copy:
content: |
{{ user.password }}
{{ user.password }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentionally the same thing twice?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. As you can see from the shell command later, the contents of this file are just catted into smbpasswd. smbpasswd asks for the password and then password confirmation right after, so we need to enter it twice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a comment to that effect to prevent someone "fixing" it in the future :)

dest: "{{ tmpfile.path }}"
changed_when: false
no_log: true
tags:
- samba
- samba_user

- name: Create/update samba users
shell: >
set -o nounset -o pipefail -o errexit &&
(
(pdbedit --user={{ user.name }} \
--configfile={{ samba_configuration }} \
2>&1 > /dev/null
) \
&& \
( \
cat "{{ tmpfile.path }}" \
| smbpasswd -s {{ user.name }} \
) \
) \
|| cat "{{ tmpfile.path }}" \
| smbpasswd -s -a {{ user.name }}
args:
executable: /bin/bash
register: create_user_output
changed_when: "'Added user' in create_user_output.stdout"
tags:
- samba
- samba_user

always:
- name: Remove tmpfile
file:
path: "{{ tmpfile.path }}"
state: absent
changed_when: false
tags:
- samba
- samba_user