Ask Your Question

Get User ID / Managing Port Numbers

asked 2014-06-18 14:45:57 -0500

Gibbs gravatar image

updated 2014-06-18 14:55:56 -0500

I have a custom module that uses other modules to set 'good' values for internal use. For example creating a virtualhost takes two hiera lines and automatically figures out home and log directories etc etc.

I am using PHP FPM with Ubuntu 14.04 and need a way to calculate port numbers so other developers don't have to specify them. Each user on the system has their own FPM pool (which requires a unique port for this setup). As each pool has a unique user my initial thought was to get the users id and prefix a number. For example:

3 (prefix) + 1009 (uid) = Port 31009

Can Puppet get a users id? If not what is a better approach to generate port numbers that can be retrieved for later use in a module?

edit retag flag offensive close merge delete


Wow. That is a problem that I'm looking for to fix as well. I have read documentation on this topic but haven't used it yet in my modules - So i have only theoretical knowledge

3h4x gravatar image3h4x ( 2014-06-20 03:10:55 -0500 )edit

Oh yeah, and you could change the question to something more universal because it's not just for dealing with that one problem, it should be generic like "What is the best way to assign group of system variables in facter?'

3h4x gravatar image3h4x ( 2014-06-20 03:12:07 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-06-20 04:33:32 -0500

updated 2014-06-20 04:34:31 -0500

I think you might achieve this with 'External Facts' as described here: .

So you could put a small script (remember to set the executable bit) under /etc/facter/facts.d/ (or /etc/puppetlabs/facter/facts.d/ for PE) which reads /etc/passwd and outputs key-value pairs, e.g.:

cat /etc/passwd | awk -F: '{print $1 "_userid=" $3}'

Here I have appended "_userid" to avoid making a mess of the set of existing facts.

Of course, you need a way to pick up those facts in you module. I'm not sure if you can dynamically construct the key-name (e.g. peter_userid) of a fact you want to reference? If this is not possible, then you may have to skip the append of "_userid", and accept the mess in the set of facts.

NOTE: I haven't tested this myself.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-06-18 14:45:57 -0500

Seen: 439 times

Last updated: Jun 20 '14