How to set password for user in Ansible

George Shuklin
OpsOps
Published in
1 min readMay 25, 2018

Ansible is used for different purposes. Sometimes it’s a core business process where you need to follow all possible best practices and more. Sometimes it’s knock-off script for laboratory environments where you are completely fineto store passwords in the git. If those environments are protected against simple probing bots, that’s enough.

And sometimes one need to give access to labs to number of people. If list of those people is not explicitly known, ssh keys are inconvenient. Account with password is the best for that.

Ansible can set password, but it aims for best practices. Here I’m demoting it to convenience.

How to set a password for a user’s account stored in a plain-text form in the inventory/or group variables?

- name: Set root password
user:
name: root
password: '{{root_password|password_hash("sha512", "{{salt}}") }}'

root_password has a plain-text password for user ‘root’, (f.e. “iHbs2Seneab”)

salt stores any value. (f.e. “mysaltvalue”).

Insecure? Yes. Convenient? Yes.

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.