- name: Add new SFTP user (user provided by prompt)'
hosts: '{{ target }}'
vars:
pwd_alias: "{{ lookup('password', '/dev/null length=15 chars=ascii_letters') }}"
user_to_add: "{{ newuser }}"
tasks:
- set_fact:
my_pass: "{{ pwd_alias | password_hash('sha512') }}"
- name: Create user
user:
name: "{{ user_to_add }}"
password: "{{ my_pass }}"
shell: /bin/bash
create_home: yes
home: "/home/sftp/{{ user_to_add }}"
group: cgred
- debug:
msg: "{{ pwd_alias }},{{ my_pass }}"
当我运行它时,它会做它应该做的事情。它创建我指定的用户和主目录。它还会打印出密码和哈希值,但无论我做什么,我都无法记录对该用户的更改。
任何有关如何正确获取分配给该用户的密码的建议将不胜感激。
慕沐林林
相关分类