Ask Your Question
0

checking a configuration file before updating a setting in another file

asked 2016-08-29 10:25:33 -0600

busyadmin gravatar image

I am trying to implement automatic home directory creation on our server estate everywhere except where autofs has been configured to provide a home directory:

***if $lsbmajdistrelease == 5 {
                             exec {'check_no_autofshome':
                                    command => '/bin/false',
                                    onlyif => '/bin/grep "^/home" /etc/auto.master >/dev/null 2>&1',
                                  }
                             file_line {'Add line to support automatic home directory creation in RHEL 5':
                                         line => 'session    required   pam_mkhomedir.so skel=/etc/skel/ umask=0077',
                                         path => '/etc/pam.d/system-auth',
                                         require => Exec["check_no_autofshome"],
                                       }
                           }***

For RHEL6/7 this is easy because authconfig will correctly specify the umask, on RHEL 5 a umask of 0022 will be set, I digress....

The code block above functions as desired however a home directory specification in /etc/auto.master results in the following error from exec: err: /Stage[main]/Homedir::Mkhomedir/Exec[check_no_autofshome]/returns: change from notrun to 0 failed: /bin/false returned 1 instead of one of [0] at /etc/puppet/modules/homedir/manifests/mkhomedir.pp:48

I haven't been able to find a way of suppressing it or rewriting my code to create the desired outcome without an error message.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-09-01 13:06:05 -0600

lupin gravatar image

You can create a custom facts to do that. i.e

Ouput without /home set

[root@ha-centos7 module0]# grep '^/home' /etc/auto.master
[root@ha-centos7 module0]# puppet apply tests/init.pp 
Notice: Compiled catalog for ha-centos7.home in environment production in 0.25 seconds
Notice: Finished catalog run in 0.02 seconds

Set /home and output

[root@ha-centos7 module0]# vim /etc/auto.master
[root@ha-centos7 module0]# grep '^/home' /etc/auto.master
/home
[root@ha-centos7 module0]# puppet apply tests/init.pp 
Notice: Compiled catalog for ha-centos7.home in environment production in 0.23 seconds
Notice: /home is set on auto.master
Notice: /Stage[main]/Module0/Notify[/home is set on auto.master]/message: defined 'message' as '/home is set on auto.master'
Notice: Finished catalog run in 0.02 seconds

custom facts

[root@ha-centos7 module0]# cat lib/facter/autofs_home.rb
Facter.add('autofs_home') do
  setcode do
    begin
      f = File.new("/etc/auto.master", "r")
      while (line = f.gets)
         if line.start_with?("/home")
           break true
         else
           nil
         end
      end
    rescue
      nil
    end
 end
end

Then on your manifest you can

if $lsbmajdistrelease == 5 and $::autofs_home {
   file_line {'foo': 
   }
}
edit flag offensive delete link more

Comments

Only downfall of this is if you are setting the auto.master configuration in puppet, it would take two puppet runs to converge on the final configuration, as the facts are checked once before the catalog is compiled

DarylW gravatar imageDarylW ( 2016-09-02 09:03:10 -0600 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2016-08-29 10:25:33 -0600

Seen: 39 times

Last updated: Sep 01 '16