How to fix WPCLI Error: Role doesn't exist: admin

Problem:

While trying to create a user using wpcli using a command such as

wp user create uli [email protected] --role=admin --user_pass=abc123abc

you see the following error message:

Error: Role doesn't exist: admin

Solution

Run

wp role list

to list all roles. By default, these roles are:

+---------------+---------------+
| name          | role          |
+---------------+---------------+
| Administrator | administrator |
| Editor        | editor        |
| Author        | author        |
| Contributor   | contributor   |
| Subscriber    | subscriber    |
| SEO Manager   | wpseo_manager |
| SEO Editor    | wpseo_editor  |
+---------------+---------------+

You have to use the value from the second column in the wp user create command.

For example, in order to create an admin user, use --role=administrator, e.g.:

wp user create uli [email protected] --role=administrator --user_pass=abc123abc