[英]Add a custom sudoers in Puppet
我是Puppet的新手,已经在forge中下载了central_auth模块来实现Linux(CentOS)服务器上的AD登录。 经过一些调整后,我终于可以使用 AD 登录了。 我现在要做的是根据节点的 yaml 文件中的值在 /etc/sudoers.d 中添加自定义 sudoers 文件。 问题:/etc/sudoers.d/customsudo 已创建,但内容不正确。
这是我的配置:
在清单/init.pp
class central_auth (
# Class parameters are populated from External(hiera)/Defaults/Fail
Boolean $manage_auth = false,
Boolean $enable_sssd = true,
Boolean $enable_pam_access = false,
Boolean $manage_pam_files = true,
) {
if $manage_auth {
class { 'central_auth::install': }
-> class { 'central_auth::config': }
-> class { 'central_auth::pam': }
-> class { 'central_auth::join_ad': }
-> class { 'central_auth::service': }
-> class { 'central_auth::custom_sudoers': }
}
}
在清单/custom_sudoers.pp
class central_auth::custom_sudoers (
Any $sudoersgrp = $central_auth::sudoersgrp,
) {
if $sudoersgrp {
file { '/etc/sudoers.d/customsudo':
ensure => present,
owner => 'root',
group => 'root',
mode => '0644',
content => template( 'central_auth/sudogroup.epp' ),
} } }
在模板/sudogroup.epp
%<%= $sudoersgrp %> ALL=(ALL) NOPASSWD: ALL
在节点的 yaml 文件中,我添加了这些行来调用 central_auth class:
classes:
- central_auth
central_auth::manage_auth: true
central_auth::enable_sssd: true
central_auth::enable_pam_access: true
central_auth::manage_pam_files: true
central_auth::sudoersgrp: 'CustomSudoers'
在客户端创建的 /etc/sudoers.d/customsudo 文件中,它只出现如下所示。 我希望“CustomSudoers”在 manifests/custom_sudoers.pp 中的 $sudoersgrp 变量上传递,这将创建 /etc/sudoers.d/customsudo 文件。
它在 /etc/sudoers.d/customsudo 中应该是什么样子:
%CustomSudoers ALL=(ALL) NOPASSWD: ALL
在观看 Udemy 中的教程后现已修复。 :)
在 init.pp 中
class central_auth (
# Class parameters are populated from External(hiera)/Defaults/Fail
Boolean $manage_auth = false,
Boolean $enable_sssd = true,
Boolean $enable_pam_access = false,
Boolean $manage_pam_files = true,
Any $sudoersgrp = undef,
) {
if $manage_auth {
class { 'central_auth::install': }
-> class { 'central_auth::config': }
-> class { 'central_auth::pam': }
-> class { 'central_auth::join_ad': }
-> class { 'central_auth::service': }
-> class { 'central_auth::custom_sudoers': }
}
}
在清单/custom_sudoers.pp
class central_auth::custom_sudoers (
Any $sudoersgrp = $central_auth::sudoersgrp,
) {
if $sudoersgrp {
file { '/etc/sudoers.d/customsudo':
ensure => present,
owner => 'root',
group => 'root',
mode => '0644',
content => epp('central_auth/sudogroup.epp', {
'sudoersgrp' => $sudoersgrp,
} ),
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.