mirror of
				https://github.com/krislamo/puppet-fluentd
				synced 2025-11-03 18:28:34 +00:00 
			
		
		
		
	added ::fluentd::user
this will manage the user if is set to true. This will add the td-agent user to the user group 'adm', so td-agent can view log files under /var/log/*.
This commit is contained in:
		@@ -27,7 +27,19 @@
 | 
				
			|||||||
#   Service ensure
 | 
					#   Service ensure
 | 
				
			||||||
#   Default: 'running'
 | 
					#   Default: 'running'
 | 
				
			||||||
# [*service_enabled*]
 | 
					# [*service_enabled*]
 | 
				
			||||||
#   Defines if the service should be enabled, defaults to 'true'
 | 
					#   Defines if the service should be enabled
 | 
				
			||||||
 | 
					#   Default: 'true'
 | 
				
			||||||
 | 
					# [*user_manage*]
 | 
				
			||||||
 | 
					#   Defines if the user should be manage, which will add the user
 | 
				
			||||||
 | 
					#   to groups defined in $user_groups.
 | 
				
			||||||
 | 
					#   For example to be able to view the /var/log directory with group adm
 | 
				
			||||||
 | 
					#   Default: 'true'
 | 
				
			||||||
 | 
					# [*user_name*]
 | 
				
			||||||
 | 
					#   Default: 'td-agent'
 | 
				
			||||||
 | 
					# [*user_group*]
 | 
				
			||||||
 | 
					#   Default: 'td-agent'
 | 
				
			||||||
 | 
					# [*user_groups*]
 | 
				
			||||||
 | 
					#   Default: '["adm"]'
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# Examples
 | 
					# Examples
 | 
				
			||||||
# --------
 | 
					# --------
 | 
				
			||||||
@@ -52,8 +64,10 @@ class fluentd (
 | 
				
			|||||||
  $config_path             = $::fluentd::params::config_path,
 | 
					  $config_path             = $::fluentd::params::config_path,
 | 
				
			||||||
  $conf_dir                = $::fluentd::params::conf_dir,
 | 
					  $conf_dir                = $::fluentd::params::conf_dir,
 | 
				
			||||||
  $config_file             = $::fluentd::params::config_file,
 | 
					  $config_file             = $::fluentd::params::config_file,
 | 
				
			||||||
 | 
					  $user_manage             = $::fluentd::params::user_manage,
 | 
				
			||||||
  $user_name               = $::fluentd::params::user_name,
 | 
					  $user_name               = $::fluentd::params::user_name,
 | 
				
			||||||
  $user_group              = $::fluentd::params::user_group,
 | 
					  $user_group              = $::fluentd::params::user_group,
 | 
				
			||||||
 | 
					  $user_groups             = $::fluentd::params::user_groups,
 | 
				
			||||||
) inherits fluentd::params {
 | 
					) inherits fluentd::params {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # parameter validation
 | 
					  # parameter validation
 | 
				
			||||||
@@ -72,12 +86,14 @@ class fluentd (
 | 
				
			|||||||
  # class calls
 | 
					  # class calls
 | 
				
			||||||
  include '::fluentd::repo'
 | 
					  include '::fluentd::repo'
 | 
				
			||||||
  include '::fluentd::install'
 | 
					  include '::fluentd::install'
 | 
				
			||||||
 | 
					  include '::fluentd::user'
 | 
				
			||||||
  include '::fluentd::config'
 | 
					  include '::fluentd::config'
 | 
				
			||||||
  include '::fluentd::service'
 | 
					  include '::fluentd::service'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # dependencies
 | 
					  # dependencies
 | 
				
			||||||
  Class['::Fluentd::Repo']    ->
 | 
					  Class['::Fluentd::Repo']    ->
 | 
				
			||||||
  Class['::Fluentd::Install'] ->
 | 
					  Class['::Fluentd::Install'] ->
 | 
				
			||||||
 | 
					  Class['::Fluentd::User']    ->
 | 
				
			||||||
  Class['::Fluentd::Config']  ->
 | 
					  Class['::Fluentd::Config']  ->
 | 
				
			||||||
  Class['::Fluentd::Service']
 | 
					  Class['::Fluentd::Service']
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,8 +13,10 @@ class fluentd::params {
 | 
				
			|||||||
  $conf_dir    = "${config_path}/conf.d"
 | 
					  $conf_dir    = "${config_path}/conf.d"
 | 
				
			||||||
  $config_file = "${config_path}/td-agent.conf"
 | 
					  $config_file = "${config_path}/td-agent.conf"
 | 
				
			||||||
  # user params
 | 
					  # user params
 | 
				
			||||||
 | 
					  $user_manage = true
 | 
				
			||||||
  $user_name   = 'td-agent'
 | 
					  $user_name   = 'td-agent'
 | 
				
			||||||
  $user_group  = 'td-agent'
 | 
					  $user_group  = 'td-agent'
 | 
				
			||||||
 | 
					  $user_groups = ['adm']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  case $::osfamily {
 | 
					  case $::osfamily {
 | 
				
			||||||
    'Debian': {
 | 
					    'Debian': {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										13
									
								
								manifests/user.pp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								manifests/user.pp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					# Configure package
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					class fluentd::user inherits fluentd {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if $::fluentd::user_manage {
 | 
				
			||||||
 | 
					    user { 'fluentd':
 | 
				
			||||||
 | 
					      name    => $::fluentd::user_name,
 | 
				
			||||||
 | 
					      gid     => $::fluentd::user_group,
 | 
				
			||||||
 | 
					      groups  => $::fluentd::user_groups,
 | 
				
			||||||
 | 
					      require => Class['Fluentd::Install'],
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										22
									
								
								spec/classes/fluentd_user_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								spec/classes/fluentd_user_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					require 'spec_helper'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					describe 'fluentd::user', :type => :class do
 | 
				
			||||||
 | 
					  let(:facts) {
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      :osfamily        => 'Debian',
 | 
				
			||||||
 | 
					      :lsbdistid       => 'Ubuntu',
 | 
				
			||||||
 | 
					      :operatingsystem => 'Ubuntu',
 | 
				
			||||||
 | 
					      :lsbdistcodename => 'precise',
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  describe 'when called with no parameters on Ubuntu' do
 | 
				
			||||||
 | 
					    it {
 | 
				
			||||||
 | 
					      should contain_user('fluentd').with({
 | 
				
			||||||
 | 
					        'name'   => 'td-agent',
 | 
				
			||||||
 | 
					        'gid'    => 'td-agent',
 | 
				
			||||||
 | 
					        'groups' => ['adm']
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
		Reference in New Issue
	
	Block a user