# Creating a System User still creates a home directory

**URL:** <https://forum.ansible.com/t/creating-a-system-user-still-creates-a-home-directory/20135>\
**Category:** Ansible Project\
**Created:** [January 6, 2016, 6:58pm UTC](https://forum.ansible.com/t/creating-a-system-user-still-creates-a-home-directory/20135 "2016-01-06T18:58:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uberteck](https://avatars.discourse-cdn.com/v4/letter/u/e274bd/32.png) [@Uberteck](https://forum.ansible.com/u/Uberteck)\
**Post date:** [January 6, 2016, 6:58pm UTC](https://forum.ansible.com/t/creating-a-system-user-still-creates-a-home-directory/20135/1 "2016-01-06T18:58:29Z")

</div>

Creating a user using the core user module and using the ‘system’ property still seems to create a home directory:

`

- name: create test user  
user:  
name=test  
system=yes  
`

The resulting user has a home directory when applying this to a Centos 7 host.

According to ‘man useradd’, creating a system account should override any defaults to create a home directory:

`  
-r, --system

Create a system account.

System users will be created with no aging information in

/etc/shadow, and their numeric identifiers are chosen in the

SYS\_UID\_MIN-SYS\_UID\_MAX range, defined in /etc/login.defs, instead

of UID\_MIN-UID\_MAX (and their GID counterparts for the creation of

groups).

Note that useradd will not create a home directory for such an

user, regardless of the default setting in /etc/login.defs

(CREATE\_HOME). You have to specify the -m options if you want a

home directory for a system account to be created.  
`

Am I doing something wrong or is this a bug?

Cheers,

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 6, 2016, 8:36pm UTC](https://forum.ansible.com/t/creating-a-system-user-still-creates-a-home-directory/20135/2 "2016-01-06T20:36:12Z")

</div>

Does this happen if you supply `createhome=no`?

Also is the home directory created on the initial user creation or subsequent runs?

It looks like the user module does add `-r` to the command, however I see some code that may create the homedir regardless of `system=yes` on subsequent runs after the user is already created unless `createhome=no` is specified:

[https://github.com/ansible/ansible-modules-core/blob/0930a44816d717052f8f6e7d37b74ea200b0d661/system/user.py#L2148-L2156](https://github.com/ansible/ansible-modules-core/blob/0930a44816d717052f8f6e7d37b74ea200b0d661/system/user.py#L2148-L2156)

Not sure if we would need to make that check if `system=yes` was specified.

---

<div class="post-metadata">

**Author:** ![Uberteck](https://avatars.discourse-cdn.com/v4/letter/u/e274bd/32.png) [@Uberteck](https://forum.ansible.com/u/Uberteck)\
**Post date:** [January 7, 2016, 6:42pm UTC](https://forum.ansible.com/t/creating-a-system-user-still-creates-a-home-directory/20135/3 "2016-01-07T18:42:58Z")

</div>

No, adding ‘createhome=no’ stops it creating a home directory and is what I am currently using (in addition to system=yes) as a workaround to get the desired result.

I just tested and the home directory is created on the first run - on initial user creation.

I also tested manually running a ‘useradd -r’ to make sure it wasn’t something funky with my OS build (vagrant box - lots stripped out) but that works as expected - no home directory.

If the command is supplying ‘-r’ then it would seem a good call that something is overriding that somewhere and explicitly forcing the creation of a home directory. However it seems to happen on the first run for me, so unless that ‘missing homedirs’ check is executed on first run, somewhere else might need looking at too.
