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
  • 56,709
  • 26
  • 150
  • 232

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,941
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
  • 756