Created
December 10, 2015 00:39
-
-
Save ianling/13782cd2293a1ea08035 to your computer and use it in GitHub Desktop.
Sets the root password of a remote host to a randomly generated one. The new password gets stored locally in plaintext at /backup/passwords/<hostname>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Change the root password and store the updated password locally in /backup/passwords/<hostname> | |
hosts: all | |
remote_user: backup | |
vars: | |
plaintextpw: "{{ lookup('password', '/backup/passwords/'+inventory_hostname+' chars=ascii_letters,digits,hexdigits,punctuation,, length=20') }}" | |
tasks: | |
- name: Remove the old password file, if it exists | |
local_action: file path=/backup/passwords/{{ inventory_hostname }} state=absent | |
- name: Generate the hashed password from plaintextpw | |
local_action: command /usr/bin/mkpasswd --method=SHA-512 {{ plaintextpw }} | |
register: mkpasswd_output | |
- name: Change the root user's password | |
user: name=root | |
password={{ mkpasswd_output.stdout }} | |
update_password=always |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment