Set default shell for existing user with puppet

I'd like to set the default shell to zsh in Puppet. Preferably for the current user because I just run my modules as puppet apply mymodule.pp since I store my configuration that I use across multiple machines in git.

How can I set the default shell using puppet?


Solution 1:

If you want to set the shell of an existing user, simply do:

user { "theuser":
  ensure => present,
  shell  => "/bin/zsh",
}

If you want to set the shell of whatever user Puppet is happening to run as, you can make use of the $id fact which returns the name of the current user. This feels a little bit magical to me, and may result in undesired outcomes, like if you're running as the puppet user with a puppet agent run and you end up setting a shell for a user that shouldn't have interactive logins.

That would be done like:

user { $id:
  ensure => present,
  shell  => "/bin/zsh",
}

Note: the "ensure => present" is optional.