How get "user id" in the operating system?

31 views
Skip to first unread message

Kirill K

unread,
May 11, 2014, 3:19:21 AM5/11/14
to puppet...@googlegroups.com
Hi,

file.pp:
сlass keys {
file { '/etc/ssh/keys':
ensure => directory,
}
#I don't understand how to get variable from the operating system?
$kolchanov_id = "id kolchanov"

#If such user available, need copy him public key to the folder. Else, remove an existing public key.
if $kolchanov_id == true {
            file { '/etc/ssh/keys/kolchanov_keys':
                mode => '600',
                owner => 'kolchanov',
                group => 'users',
                source => 'puppet:///files/sshkeys/kolchanov_keys',
                require => file['/etc/ssh/keys']
                }
} else { exec { "rm -rf /etc/ssh/keys/kolchanov_keys":
                path => ["/bin", "/usr/bin"],
                }
        }
}

Thanks!

David Schmitt

unread,
May 11, 2014, 11:34:27 AM5/11/14
to puppet...@googlegroups.com
Hi,

Puppet's basic mode of operation is to *tell* systems whether they
should have both the user and the key or should remove both:

class kolchanov($ensure = present) {
user { 'kolchanov': ensure => $ensure, ... }
file { '/etc/ssh/keys/kolchanov_keys': ensure => $ensure, ... ]
}

If you really have to depend on an external process creating that user
and have to react to this, then you need to code up a fact that queries
the system. This information will be run by the agent everytime before
contacting the master. See the facter documentation for more details:

http://docs.puppetlabs.com/guides/custom_facts.html


Good luck and have fun, David

On 2014-05-11 09:19, Kirill K wrote:
> Hi,
>
> file.pp:
> сlass keys {
> file { '/etc/ssh/keys':
> ensure => directory,
> }
> *#I don't understand how to get variable from the operating system?*
> $kolchanov_id = "id kolchanov"
>
> *#If such user available, need copy him public key to the folder. Else,
> remove an existing public key.*
Reply all
Reply to author
Forward
0 new messages