- From: Alexander Skwar <
>
- To:
- Subject: [chef] Check if a user exists?
- Date: Wed, 23 Sep 2015 10:15:15 +0200
Hello
We're using an
IPA server to store user accounts and such and Ubuntu clients with
FreeIPA to access this. I would now like to do something, based on the existence of a user account in IPA.
How can I check if a user exists?
Ohai queries the users on the system for you:
if node['etc']['passwd']['random']
# Do deploy
end
But this only works with local accounts; it does not work with accounts in IPA. In our nsswitch.conf, there's:
$ grep passwd /etc/nsswitch.conf
With getent, I can query accounts.
ask:*:10000:10000:Alexander Skwar:/home/ask:/usr/bin/zsh
$ getent passwd example-does-not-exist
local:x:1000:1000::/home/local:/bin/zsh
"ask" is stored in IPA; "example-does-not-exist" is a non-existant account; "local" is a user from /etc/passwd.
But "node['etc']['passwd']['ask']" is "nil". And "node['etc']['passwd']['local']" is not nil.
How can I check if a user exists? Do I really have to resort to calling getent?
Thanks,
Alexander
- [chef] Check if a user exists?, Alexander Skwar, 09/23/2015
Archive powered by MHonArc 2.6.16.