salt: State user.present will fail to create home if user exists and homedir doesn't

Ran into this today, it appears that in one of our installs, the user got created at some point, but their home dir didn’t. When I ran the highstate today, it errored out with the following: local:

ID: xxxxxxx
Function: user.present
Result: False
Comment: These values could not be changed: {'homeDoesNotExist': '/home/xxxxxxx'}
Started: 11:30:43.057275
Duration: 6.189 ms
Changes:

It looks like here the change doesn’t get made, but reports it back as a change that is remaining.

https://github.com/saltstack/salt/blob/2014.7/salt/states/user.py#L110

Should the user.add module be called to create the home dir or should user.chhome be modified to create a homedir if one doesn’t exist.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 34 (21 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve run into a similar issue, and in the hopes of helping folks stumbling across this bug report, I’ve documented the steps I took to resolve it.

In brief

Try manually changing the user home directory with usermod and see if any errors are given.

To avoid this confusion, Salt could be more informative on why the values could not be changed.

Problem

----------
          ID: app.user-basic
    Function: user.present
        Name: existing-user
      Result: False
     Comment: These values could not be changed: {u'home': u'/path/to/new/home'}
     Started: 17:40:16.369636
    Duration: 20.876 ms
     Changes:

Troubleshooting

I found out the root cause by trying to manually run the command:

admin@box:~$ sudo usermod --home /path/to/new/home existing-user
usermod: user existing-user is currently used by process 18234

Solution

In this case, I needed to make sure the service was stopped (and the user not in use) before changing the home directory:

# Stop the service if running and changes will be made
app.user-basic.stop-for-changes:
  service.dead:
    - name: existing-user-service
    - prereq:
      # Stop service before making changes
      - user: app.user-basic

# Set up the user
app.user-basic:
  user.present:
    - name: existing-user
    - system: True
    - createhome: False # Handled below
    - home: /path/to/new/home

# [...removed other bits of configuration...]

# Start the service
app.service:
  service.running:
    - name: existing-user-service
    - enable: True

This resulted in success!

Excerpt of Salt call output
----------
          ID: app.user-basic.stop-for-changes
    Function: service.dead
        Name: existing-user-service
      Result: True
     Comment: Service existing-user-service was killed
     Started: 17:45:29.589417
    Duration: 100.504 ms
     Changes:   
              ----------
              existing-user-service:
                  False
----------
          ID: app.user-basic
    Function: user.present
        Name: existing-user
      Result: True
     Comment: Updated user existing-user
     Started: 17:45:29.693622
    Duration: 26.762 ms
     Changes:   
              ----------
              home:
                  /path/to/new/home
[...]
----------
          ID: app.service
    Function: service.running
        Name: existing-user-service
      Result: True
     Comment: Service existing-user-service is already enabled, and is running
     Started: 17:45:31.084540
    Duration: 121.158 ms
     Changes:   
              ----------
              existing-user-service:
                  True

If this does not fix your issue, try manually changing the home directory with usermod. There may be something else going on.

Reviewed in Tuesday Triage, we do not believe this is a current issue, closing. If anyone on this issue does experience it or someone else, please open a new issue with details from the issue template. Thank you!

@digitalcircuit, that looks like the beginning of a fix, but I wonder if further corners are hiding as well. I agree that more articulate reporting that reaches closer to root causes comprises a major portion of the solution.

I am still having the same issue of changing an existing user’s home directory with 2017.7.5:

nrpe-nagios_user:
  user.present:
    - name: nagios
    - home: /home/nagios
    - fullname: 'Nagios System User'
    - shell: /bin/bash
    - require:
      - pkg: nrpe-pkgs
----------
          ID: nrpe-nagios_user
    Function: user.present
        Name: nagios
      Result: False
     Comment: These values could not be changed: {'home': '/home/nagios'}
     Started: 16:52:04.045301
    Duration: 94.0 ms
     Changes:
Salt Version:
           Salt: 2017.7.5

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.7.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8.1
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.14 (default, Jan 31 2018, 02:12:13)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.5.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: centos 6.9 Final
         locale: UTF-8
        machine: x86_64
        release: 2.6.32-696.23.1.el6.x86_64
         system: Linux
        version: CentOS 6.9 Final
# grep nagios /etc/passwd
nagios:x:498:498:Nagios System User,,,:/var/spool/nagios:/bin/bash

Any idea on a fix?