Search code examples
ansibleansible-ad-hoc

Deleting multiple users with Ansible ad-hoc command


When running Ansible ad-hoc to remove users I was unable to feed multiple items to module. Like this:

ansible -i my_inv all -m user -a"name={{ users }} state=absent" --check --extra-vars='{"users":["user1","user2"]}'

the output is:

    server1 | SUCCESS => {
    "changed": false,
    "name": "['user1', 'user2']",
    "state": "absent"
     }

it seems to be not opening array correctly. Making json file also didnt work.

    {
   "users":["user1","user2"]
    }

Is there any way to do it without writing a role?


Solution

  • No.

    name parameter of user module takes a string as an argument, not a list.

    You need either to loop (and for that you'd need a play - not necessarily a role), or run ansible executable several times.