# add user via adhoc

**URL:** <https://forum.ansible.com/t/add-user-via-adhoc/25318>\
**Category:** Ansible Project\
**Created:** [August 24, 2017, 3:09am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318 "2017-08-24T03:09:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juraj\_Papic1](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Juraj\_Papic1](https://forum.ansible.com/u/Juraj_Papic1)\
**Post date:** [August 24, 2017, 3:09am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/1 "2017-08-24T03:09:55Z")

</div>

Hi all

I want to add users via commands

all - user -a “name=test password=test” -s -K

is not workingplease help.

.

---

<div class="post-metadata">

**Author:** ![Soniya\_panwar](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Soniya\_panwar](https://forum.ansible.com/u/Soniya_panwar)\
**Post date:** [August 24, 2017, 5:07am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/2 "2017-08-24T05:07:21Z")

</div>

Hey Tcpip,

Can you please elaborate what exactly error you are getting after running this command because its working fine for me.

You need to provide more info like

- the env (os, distro, version, etc) you are running ansible from

- the full output (with the verbosity level raised by adding the ‘-vvvv’ cli opts to this command)

- what you expect to happen

---

<div class="post-metadata">

**Author:** ![Juraj\_Papic1](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Juraj\_Papic1](https://forum.ansible.com/u/Juraj_Papic1)\
**Post date:** [August 24, 2017, 8:03am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/3 "2017-08-24T08:03:02Z")

</div>

Hello Soniya,

This is the output I have and for what I can see none of my commands are working.

Servers 14.04  
2.3.1.0

version = 2.7.6

Thanks!

This is the output I have

Loading callback plugin minimal of type , v20 from /usr/lib/python27/-packages//plugins/callback/ **init**  
META: handlers  
Using module file /usr/lib/python27/-packages//modules/system/user  
\<172.22.15.3\> ESTABLISH LOCAL CONNECTION FOR USER: root  
\<172.22.15.3\> EXEC /bin/sh -c ‘echo ~ && sleep 0’  
Using module file /usr/lib/python27/-packages//modules/system/user  
\<172.22.14.3\> ESTABLISH LOCAL CONNECTION FOR USER: root  
\<172.22.14.3\> EXEC /bin/sh -c ‘echo ~ && sleep 0’  
\<172.22.14.3\> EXEC /bin/sh -c ’ 77 && mkdir -p “`echo /home///tmp/--1503561664.69-1922608506894`” && echo --1503561664.69-1922608506894=“`echo /home///tmp/--1503561664.69-1922608506894`” && sleep 0’  
\<172.22.15.3\> EXEC /bin/sh -c ’ 77 && mkdir -p “`echo /home///tmp/--1503561664.68-54531949999364`” && echo --1503561664.68-54531949999364=“`echo /home///tmp/--1503561664.68-54531949999364`” && sleep 0’  
\<172.22.14.3\> PUT /tmp/tmpqpuHN1 TO /home///tmp/–1503561664.69-1922608506894/user  
\<172.22.14.3\> EXEC /bin/sh -c ‘chmod u+x /home/juraj/.ansible/tmp/ansible-tmp-1503561664.69-1922608506894/ /home/juraj/.ansible/tmp/ansible-tmp-1503561664.69-1922608506894/user.py && sleep 0’  
\<172.22.15.3\> PUT /tmp/ TO /home///tmp/–1503561664.68-54531949999364/user  
\<172.22.15.3\> EXEC /bin/sh -c ‘chmod u+x /home/juraj/.ansible/tmp/ansible-tmp-1503561664.68-54531949999364/ /home/juraj/.ansible/tmp/ansible-tmp-1503561664.68-54531949999364/user.py && sleep 0’  
\<172.22.14.3\> EXEC /bin/sh -c ‘/usr/bin/python /home/juraj/.ansible/tmp/ansible-tmp-1503561664.69-1922608506894/user.py; rm -rf “/home/juraj/.ansible/tmp/ansible-tmp-1503561664.69-1922608506894/” \> /dev/null 2\>&1 && sleep 0’  
\<172.22.15.3\> EXEC /bin/sh -c ‘/usr/bin/python /home/juraj/.ansible/tmp/ansible-tmp-1503561664.68-54531949999364/user.py; rm -rf “/home/juraj/.ansible/tmp/ansible-tmp-1503561664.68-54531949999364/” \> /dev/null 2\>&1 && sleep 0’  
Ubu1 | SUCCESS =\> {  
“”: false,  
“”: false,  
“”: “”,  
“”: 1001,  
“”: “/home/**",  
“”: {  
“module\_args”: {  
“”: false,  
“”: null,  
“”: true,  
“”: null,  
“”: false,  
“generate\_ssh\_key”: null,  
“”: null,  
“”: null,  
“”: null,  
“login\_class”: null,  
“move\_home”: false,  
“”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“non\_unique”: false,  
“”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“”: false,  
“”: null,  
“”: null,  
“”: null,  
“ssh\_key\_bits”: 0,  
“ssh\_key\_comment”: "-generated on ",  
“ssh\_key\_file”: null,  
“ssh\_key\_passphrase”: null,  
“ssh\_key\_type”: “”,  
“”: “present”,  
“”: false,  
“”: null,  
“update\_password”: “always”  
}  
},  
“move\_home”: false,  
“”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“”: “NOT\_LOGGING\_PASSWORD”,  
“”: “/bin/bash”,  
“”: “present”,  
“”: 1001  
}  
Ubu2 | SUCCESS =\> {  
“”: false,  
“”: false,  
“”: “”,  
“”: 1001,  
“”: "/home/**”,  
“”: {  
“module\_args”: {  
“”: false,  
“”: null,  
“”: true,  
“”: null,  
“”: false,  
“generate\_ssh\_key”: null,  
“”: null,  
“”: null,  
“”: null,  
“login\_class”: null,  
“move\_home”: false,  
“”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“non\_unique”: false,  
“”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“”: false,  
“”: null,  
“”: null,  
“”: null,  
“ssh\_key\_bits”: 0,  
“ssh\_key\_comment”: "-generated on ",  
“ssh\_key\_file”: null,  
“ssh\_key\_passphrase”: null,  
“ssh\_key\_type”: “”,  
“”: “present”,  
“”: false,  
“”: null,  
“update\_password”: “always”  
}  
},  
“move\_home”: false,  
“”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“”: “NOT\_LOGGING\_PASSWORD”,  
“”: “/bin/bash”,  
“”: “present”,  
“”: 1001  
}

---

<div class="post-metadata">

**Author:** ![Soniya\_panwar](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Soniya\_panwar](https://forum.ansible.com/u/Soniya_panwar)\
**Post date:** [August 24, 2017, 8:47am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/4 "2017-08-24T08:47:40Z")

</div>

These logs shows that your user is created successfully.  
if you are not able to check the user whether it is created or not than you can see the output of this command

# grep test /etc/passwd

output of this command should be like this:

test:x:1001:1001::/home/test:

And if any query please revert

---

<div class="post-metadata">

**Author:** ![Juraj\_Papic1](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Juraj\_Papic1](https://forum.ansible.com/u/Juraj_Papic1)\
**Post date:** [August 24, 2017, 8:55am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/5 "2017-08-24T08:55:14Z")

</div>

Hello,  
Yes the logs when I check the remote server nothing is created-

.!!

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 24, 2017, 9:08am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/6 "2017-08-24T09:08:59Z")

</div>

This two lines in your log indicate you are using connection=local so  
everything run on localhost and not on the remote host.

So if you check localhost you'll see the users are created there.

---

<div class="post-metadata">

**Author:** ![Soniya\_panwar](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Soniya\_panwar](https://forum.ansible.com/u/Soniya_panwar)\
**Post date:** [August 24, 2017, 9:21am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/7 "2017-08-24T09:21:28Z")

</div>

how r u verifying that user is created or not?  
can you please share your command from which you are verifying and also the output of

# grep test /etc/passwd.

---

<div class="post-metadata">

**Author:** ![Juraj\_Papic1](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Juraj\_Papic1](https://forum.ansible.com/u/Juraj_Papic1)\
**Post date:** [August 24, 2017, 9:23am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/8 "2017-08-24T09:23:28Z")

</div>

try to login with the user/pass and is not working then I just do  
/etc/password

.

---

<div class="post-metadata">

**Author:** ![Juraj\_Papic1](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Juraj\_Papic1](https://forum.ansible.com/u/Juraj_Papic1)\
**Post date:** [August 24, 2017, 10:07am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/9 "2017-08-24T10:07:39Z")

</div>

That Will be in my host file what change should I do to make this work?

Thanks

---

<div class="post-metadata">

**Author:** ![Soniya\_panwar](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Soniya\_panwar](https://forum.ansible.com/u/Soniya_panwar)\
**Post date:** [August 24, 2017, 10:16am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/10 "2017-08-24T10:16:37Z")

</div>

hey,  
the problem may be is in your password generation, may be your user has been created without password  
you can check that by these commands:

user has been created but without password:

```auto
# id test
uid=229(test) gid=1(test)
# grep -q test /etc/security/passwd && echo "password OK" || echo "NO password"
NO password

```

> > then I just do more /etc/password  
> > it is /etc/passwd.

---

<div class="post-metadata">

**Author:** ![Daniel\_JD](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Daniel\_JD](https://forum.ansible.com/u/Daniel_JD)\
**Post date:** [August 24, 2017, 10:17am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/11 "2017-08-24T10:17:17Z")

</div>

ansible all -i hostfile -m user -a “name=test password=test” -s -K

or

ansible all -i 192.168.11.11, -m user -a “name=test password=test” -s -K

there must be a comma after the ip because its a tuple.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 24, 2017, 10:21am UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/12 "2017-08-24T10:21:14Z")

</div>

It will be in your inventory.

It would be easier if you could show us the entries for those two hosts, but I  
guess you have ansible\_connection=local, just remove ansible\_connection,  
default it is set to ssh.

---

<div class="post-metadata">

**Author:** ![Juraj\_Papic1](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Juraj\_Papic1](https://forum.ansible.com/u/Juraj_Papic1)\
**Post date:** [August 24, 2017, 12:16pm UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/13 "2017-08-24T12:16:17Z")

</div>

Hello

But I was testing but I can’t see the home user. I was also trying to do copy files I have a successful out put but is not copying any file.  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![Juraj\_Papic1](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Juraj\_Papic1](https://forum.ansible.com/u/Juraj_Papic1)\
**Post date:** [August 24, 2017, 5:40pm UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/14 "2017-08-24T17:40:09Z")

</div>

@Kai

how can I fix the issue?

Thanks.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 24, 2017, 7:47pm UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/15 "2017-08-24T19:47:37Z")

</div>

I guess you did not understand what I wrote in my previous mail.  
It's obviously an error in your configuration, so you need to post your  
inventory file, without it this will be a guessing game and that is a game I  
don't play.

---

<div class="post-metadata">

**Author:** ![Juraj\_Papic1](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Juraj\_Papic1](https://forum.ansible.com/u/Juraj_Papic1)\
**Post date:** [August 24, 2017, 7:51pm UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/16 "2017-08-24T19:51:02Z")

</div>

more /etc/ansible/hosts  
[all:vars]  
ansible\_connection=local  
username=admin  
password=admin

[defaults]  
host\_key\_checking = False

[router]  
SW-LAB001 ansible\_host=10.1.99.120

[linux]  
pod1 ansible\_host=10.1.108.105  
pod2 ansible\_host=10.1.108.128  
pod3 ansible\_host=10.1.108.132  
pod4 ansible\_host=10.1.108.129  
pod5 ansible\_host=10.1.108.133  
pod6 ansible\_host=10.1.108.131  
pod7 ansible\_host=10.1.108.130  
pod8 ansible\_host=10.1.108.110  
pod9 ansible\_host=10.1.108.111  
pod10 ansible\_host=10.1.108.112

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 24, 2017, 8:02pm UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/17 "2017-08-24T20:02:58Z")

</div>

And here we have the reason.  
Here you say, all host should use ansible\_connection=local aka run all task on  
all host on localhost.

Remove that line and it will work as expected.

---

<div class="post-metadata">

**Author:** ![Juraj\_Papic1](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Juraj\_Papic1](https://forum.ansible.com/u/Juraj_Papic1)\
**Post date:** [August 24, 2017, 9:01pm UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/18 "2017-08-24T21:01:52Z")

</div>

Hello Kai,

First of all thanks for your time and help, I will try the changes tonight and send you tomorrow the update.!

!

---

<div class="post-metadata">

**Author:** ![Juraj\_Papic1](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Juraj\_Papic1](https://forum.ansible.com/u/Juraj_Papic1)\
**Post date:** [August 25, 2017, 5:43pm UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/19 "2017-08-25T17:43:45Z")

</div>

Hello Kai

Thanks for your tips, it worked but I have one question, when I remove that line I start having ssh issue to my network device.

ssh unable to connect, I add back that line and it starts working.

Thanks. !!!

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 25, 2017, 6:06pm UTC](https://forum.ansible.com/t/add-user-via-adhoc/25318/20 "2017-08-25T18:06:48Z")

</div>

That's because most network equipment doesn't have python installed so the  
different module in Ansible use cli and/or api.

So, in your inventory I guess this is the one.

[router]  
SW-LAB001 ansible\_host=10.1.99.120

You have to option, add ansible\_connection=local to every host that need it in  
your inventory.

Or to the group  
[router:vars]  
ansible\_connection=local
