4

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
  vars:
  password: jbJe1oRlSZKQ6
  tasks:
    - user: name=testuser password={{password}}
Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
user163575
  • 43
  • 1
  • 1
  • 3

2 Answers2

5

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

vars:
  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())"
techraf
  • 5,831
  • 10
  • 33
  • 51
  • 1
    related when using mkpasswd: [How to create SHA512 password hashes on command line](http://unix.stackexchange.com/questions/52108/how-to-create-sha512-password-hashes-on-command-line/76337#76337) – slm Mar 31 '16 at 07: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 07: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 07:43
  • @user163575 And what are you going to do about it? – techraf Mar 31 '16 at 07:47
1
- hosts: Your_host_name
   become: True
   vars:
     # created with:
     # python -c 'import crypt; print crypt.crypt("This is my Password", "$1$SomeSalt$")'
     password: $1$SomeSalt$aIJ0bvHJBSYd307VQuuD90

   tasks:
     - user: name=tset password={{password}} state=present
mudrii
  • 736
  • 1
  • 6
  • 4