Обновить ansible/change_password.yml

This commit is contained in:
2025-12-28 15:41:01 +00:00
parent 28f91350c5
commit b8f3596abb

View File

@@ -1,24 +1,18 @@
---
- name: Utility - Change User Password
hosts: masters,workers
become: true
gather_facts: false
vars:
# Эта переменная придет из Semaphore Survey
# Переменная requested_password придет из Survey в Semaphore
target_user: "ubuntu"
tasks:
- name: Ensure passlib is installed on target (needed for hashing)
apt:
name: python3-passlib
state: present
- name: Update password for {{ target_user }} using chpasswd
become: true
# Мы передаем пароль через стандартный поток ввода (stdin) прямо в системную утилиту
shell: "echo '{{ target_user }}:{{ requested_password }}' | chpasswd"
# Чтобы пароль не светился в логах Semaphore даже в режиме Debug
no_log: true
- name: Update password for {{ target_user }}
ansible.builtin.user:
name: "{{ target_user }}"
# Мы берем сырой пароль из переменной и хешируем его прямо здесь
password: "{{ requested_password | password_hash('sha512') }}"
update_password: always
- name: Success message
- name: Confirm update
debug:
msg: "Password for {{ target_user }} has been updated!"
msg: "Password for {{ target_user }} has been updated successfully."