Hi,
I have a local.yml
playbook to setup a test environment with ansible-pull
. In this playbook I have a setup_firstuser
role that sets up the first non-root
user.
Here’s what setup_firstuser/tasks/main.yml
looks like:
- name: "Setup account and generate SSH key pair for initial user: \
{{firstuser_login}}"
ansible.builtin.user:
name: "{{firstuser_login}}"
comment: "{{firstuser_name}}"
password: >-
{{firstuser_passwd|
password_hash('sha512', 65534|
random(seed=inventory_hostname)|
string)}}
generate_ssh_key: true
ssh_key_type: ed25519
ssh_key_file: .ssh/id_ed25519
- name: "Define administrator rights for initial user: {{firstuser_login}}"
ansible.builtin.user:
name: "{{firstuser_login}}"
groups: wheel,systemd-journal
when: firstuser_admin
And here’s the corresponding setup_firstuser/defaults/main.yml
:
firstuser_login: ema
firstuser_name: EMA
firstuser_passwd: # no default
firstuser_admin: true
In the beginning of the local.yml
playbook I have a vars_prompt
section that prompts the user for a password like this :
vars_prompt:
- name: firstuser_passwd
prompt: Choose a password for user ema
default: ema123
private: true
This all works nicely so far, except every time the playbook runs, the password prompt appears. So the user either has to confirm the default password or retype his or her custom password.
Here’s what I’d like to do :
- Only prompt for the password if it hasn’t already been set.
- If there is already a password for the
ema
account then don’t show the prompt and leave the password as is.
Or maybe even better :
- Define a dead simple default password (like
ema123
) for the user in the playbook. - Let the user change the password manually (using the
passwd
command). - Once there is a password, the playbook doesn’t try to set it anymore.
Any idea on how I could achieve that ?