Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Playbook that resets user password

As an admin, it's my job to reset user passwords who still use local accounts. I'm working on converting users to domain accounts, but in the mean time, here's my little book. Check it out with context highlighting at https://gitlab.com/bgstack15/former- gists/blob/master/reset-password.yml/reset-password.yml

---
# Dependencies: pwhashgen.py from bgscripts-core, installed on ansible server
- name: book that resets password for thisuser
  hosts: all
  become: yes
  become_user: root
  become_method: sudo
  tasks:

  - name: generate pw hash
    shell: /usr/share/bgscripts/py/pwhashgen.py "{{ thispw | default('TEMP_PASSWORD_HERE') }}"
    register: thispw
    delegate_to: localhost
    changed_when: false
    run_once: true

  - user:
      name: "{{ thisuser }}"
      password: "{{ thispw.stdout }}"

  - shell: passwd -e "{{ thisuser }}"
    args:
      warn: no

Comments