How to Update User Password with Ansible

Photo by Alek Kalinowski on Unsplash

It’s very easy to change a user’s password with Ansible. Here I included 2 ways for your perusal: one with Ansible Playbook, and another one directly via command line.

Before we proceed, since Ansible does not allow us to pass a cleartext password through the User module, we’ll need to leverage on a password hashing library in Python.

Update User Password with Ansible Playbook

Setup your playbook as followed. Let’s call it change-password.yml.

This playbook aims to update the password for the user admin across all hosts.

To run this playbook, run the command as below. This will input the newpassword variable that will be used by our playbook.

Update User Password with Ansible from Command Line

Alternatively, if you prefer to run it only one time from command line directly, here’s the command that will do the same thing as the playbook above:

Personally, I prefer the playbook approach as I could then commit to Github for future reuse.

Was it helpful?

If you find this article helpful, do give me a little clap on Medium. 😄 It really makes my day to know that I have helped a fellow developer out there. Thanks!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jian Jye

I write about Laravel, PHP, and web development related articles.