SaltStack: $ HOME Users Who Don't Exist

I create user foo in the minion. The minion gives an estimate of /etc/default/useradd . This means that the salt master does not know whether the new $ HOME will be /home/foo or in our case /localhome/foo .

How can I get foo user $ HOME as a jinia variable?

I need this in the systemd service file.

I would like to avoid custom column data as this is redundant. Is there any way to get this through the grain?

Does it work during the conversion? First you need to create a custom foo , then you can create a systemd file by looking at $ HOME foo ...

This will work if the user already exists:

 {{ salt['user.info'](user).get('home') }}/foo: file.recurse: - source: salt://conf/common/foo 

Related issue: https://github.com/saltstack/salt/issues/7883

+5
source share
1 answer

Answer this question:

Is there any way to get this through the grain?

1) add the file '_grains / homeprefix.py' under file_roots specified in the main configuration file, the contents of which:

 #!/usr/bin/env python from os.path import dirname, expanduser def gethomeprefix(): # initialize a grains dictionary grains = {} # Some code for logic that sets grains like grains['homeprefix'] = dirname(expanduser("~")) return grains 

2) run sync cmd on master to synchronize grain information with minion:

 salt '*' saltutil.sync_grains 

3) run grains.get on master to check:

 salt '*' grains.get homeprefix 
+3
source

Source: https://habr.com/ru/post/1247349/


All Articles