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