0

I want to move $HOME of user postgres from /var/lib to /home via SaltStack.

Here are the steps which happen before:

  1. postgres RPM gets installed
  2. $HOME is /var/lib
  3. Database gets initialized

In this case a imperative way (tell tool to do X) would be easier than the declarative way (tell tool that you want the result which looks like X).

At least this would be easier for me, but I guess SaltStack has a hidden feature which I just don't know up to now.

There is a state user.present but I guess it does not move the home directory from one location to the next.

guettli
  • 3,113
  • 14
  • 59
  • 110

1 Answers1

1

You can set up a state which checks whether the home directory of the user is in the right place, and if not, executes some commands that move it there. Something like:

make sure postgresql home dir is under /new:
  - cmd.run:
    - unless: 'test "$(getent passwd postgresql | cut -d: -f6)" = "/new/postgresql"'
    - name: |
        service postgresql stop
        usermod --home /new/postgresql --move-home postgresql
        service postgresql start
Josip Rodin
  • 1,575
  • 11
  • 17