Can anyone help me on creating a user with password using adhoc command I have f . . .

Giffin George:
Can anyone help me on creating a user with password using adhoc command
I have faced issue in creating the password .

Andrei Andriushin:
Hi! Can you share example of your playbook/command?

Andrei Andriushin:
Playbook example for linux:

- name: Update admin's password
  ansible.builtin.user:
    name: admin
    password: "{{ password | password_hash('sha512') }}"

Giffin George:
okay

Giffin George:
I have faced issue in using this format

Giffin George:
ansible all -b -m ansible.builtin.user -a ‘name=Tim password=“202cb962ac59075b964b07152d234b70” uid=5005 comment=Dummy_user shell=/usr/sbin/nologin password_expire_max=10’

Giffin George:
can I use this mentioned for creating a user with password

Giffin George:

mkpasswd --method=sha-512

Giffin George:
i have also try to create password using sha-512

Giffin George:
but still facing the issue

Andrei Andriushin:
if you don’t want to use playbook, I guess the most easiest way is:

ansible all -b  -m  ansible.builtin.user -a '/usr/bin/yes <password> | /usr/bin/passwd <username>'

Set password using variable if you don’t want to store it in histroy:

read pass_var && ansible all -b  -m  ansible.builtin.user -a '/usr/bin/yes "$pass_var" | /usr/bin/passwd <username>'

Another way if you want to create user with password:

 pass='{{ '"'pass' | password_hash('sha512') "'}}' && ansible localhost -b  -m  ansible.builtin.user -a "name=tim password='$pass' comment=Dummy_user shell=/usr/bin/bash"

Also:
• Try to not use upper-case letters in usernames. Case-insensitivity is only about Windows
• uid will be generated automatically - you don’t need to put this
password_expire_max doesn’t supported in this mode (in my case) - use expires instead

Giffin George:
thank you

Andrei Andriushin:
Feel free to reach me :wink: