Ask Your Question

How to check a particular keyword in a line of a file using puppet manifests?

asked 2016-09-14 05:19:07 -0600

Hi , I would like to check the file /etc/password. In that file i m going to check the home directory for root user. I want a puppet manifest to check for two conditions. 1 . The home directory should be /root - root:x:0:0:root:/root:/bin/bash - need to check /root for the home directory parameter 2. The home directory can be anything but could not be "/" -root:x:0:0:root:/:/bin/bash - need to check the home directory should not be "/"

Thanks in advance.

Regards, Sathya.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-09-14 11:33:53 -0600

updated 2016-09-14 11:36:13 -0600

Use the user core resource type to ensure the proper home directory is set:

  user { 'root':
    ensure     => present,
    managehome => true,    # ensures the dir is existent
    home       => '/root',

Just checking (don't use in conjunction with the User['root'] resource example from above).

exec { 'root_home_not_root_ck':
  command => "/bin/grep '^root:' /etc/passwd | /usr/bin/cut -d':' -f6 | /bin/grep -vq '^/$'",

A conditional adjustment of the home directory [if root's home is /, then change it to /root, otherwise leave untouched], is not possible. [Well, it's possible, but bad practice].

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: 2016-09-14 05:19:07 -0600

Seen: 30 times

Last updated: Sep 14 '16