I have created an Ansible playbook to create user and set password. But it is giving me an error

ERROR: password is not a legal parameter of an Ansible Play

- hosts: all
  user: root
  password: jbJe1oRlSZKQ6
    - user: name=testuser password={{password}}

First: you need to indent password: in your playbook, because you want it to be a variable:

  password: hashed_password

If it's not indented then Ansible considers it a play parameter and throws an error because password is not.

Second: unless you are setting the password for a user on OSX, you need to provide a hashed value of a password. Follow the detailed instructions, but basically you need to provide the output of:

mkpasswd --method=SHA-512

Or install passlib with:

pip install passlib

and run:

python -c "from passlib.hash import sha512_crypt; import getpass; print sha512_crypt.encrypt(getpass.getpass())"
| improve this answer | |
  • 1
    related when using mkpasswd: How to create SHA512 password hashes on command line – slm Mar 31 '16 at 7:08
  • I am using centos 7 and i have create password using "python -c 'import crypt; print crypt.crypt("This is my Password", "test123")'". For centos unable to get packages for mkpasswd. – user163575 Mar 31 '16 at 7:20
  • thanks. now i am able to create user but when i am login with newly created user it is not accepting the passwd which i have set using ansible. – user163575 Mar 31 '16 at 7:43
  • @user163575 And what are you going to do about it? – techraf Mar 31 '16 at 7:47
- hosts: Your_host_name
   become: True
     # created with:
     # python -c 'import crypt; print crypt.crypt("This is my Password", "$1$SomeSalt$")'
     password: $1$SomeSalt$aIJ0bvHJBSYd307VQuuD90

     - user: name=tset password={{password}} state=present
| improve this answer | |

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.