My English is not so good, sorry

I use ansible ad-hoc to set some user's password Use:

python -c "from passlib.hash import sha512_crypt; import getpass; print sha512_crypt.using(rounds=5000).hash(getpass.getpass())"

generate crypted password, I got this:


run ansible ad-hoc

ansible localhost -m user -a "name=testuser password='$6$3k8DQBapvmIOZu4W$JMWhRB8kfqttNBI9NuRFZlPFpo6g4cb5v7obrqNaGZepxQ1AFCXdYv5IEU5lJFeHJXouyaQlJADcMtdMCjhXz0' state=present"

run ok, but in /etc/shadow

[root@localhost roles_test]# grep testuser /etc/shadow testuser:k8DQBapvmIOZu4W:17420:0:99999:7:::

Oops, only a part of crypted password, not a full string

ansible localhost -m user -a "name=testuser password='\$6\$3k8DQBapvmIOZu4W\$JMWhRB8kfqttNBI9NuRFZlPFpo6g4cb5v7obrqNaGZepxQ1AFCXdYv5IEU5lJFeHJXouyaQlJADcMtdMCjhXz0' state=present"

works fine, but it look like not smart .

So, how to fix this? Thx

  • Use variable and assign the encrypted password to variable and pass that variable to ansible command that will work. – Pratap Sep 11 '17 at 18:22

This is because of bash variable substitution.


ansible localhost -m user -a 'name=testuser password=$6$3k8DQBapvmIOZu4W$JMWhRB8kfqttNBI9NuRFZlPFpo6g4cb5v7obrqNaGZepxQ1AFCXdYv5IEU5lJFeHJXouyaQlJADcMtdMCjhXz0 state=present'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.