linux – 如何从puppet管理挂载的分区(fstab挂载点)

我想从puppet管理挂载的分区,包括修改/ etc / fstab和创建用作挂载点的目录. mount资源类型更新fstab就好了,但是使用file来创建挂载点有点棘手.

例如,默认情况下,目录的所有者是root,如果已安装分区的根(/)有另一个所有者,puppet将尝试更改它,我不希望这样.我知道我可以设置该目录的所有者,但为什么我应该关心挂载分区上的内容?我想做的就是装上它.有没有办法让puppet不关心用作挂载点的目录的权限?

这就是我现在正在使用的:

define extra_mount_point(
    $device,$location = "/mnt",$fstype = "xfs",$owner = "root",$group = "root",$mode = 0755,$seltype = "public_content_t"
    $options = "ro,relatime,nosuid,nodev,noexec",) {
    file { "${location}/${name}":
        ensure  => directory,owner   => "${owner}",group   => "${group}",mode    => $mode,seltype => "${seltype}",}

    mount { "${location}/${name}":
        atboot  => true,ensure  => mounted,device  => "${device}",fstype  => "${fstype}",options => "${options}",dump    => 0,pass    => 2,require => File["${location}/${name}"],}
}

extra_mount_point { "sda3": 
    device   => "/dev/sda3",fstype   => "xfs",owner    => "ciupicri",group    => "ciupicri",$options => "relatime,}

如果重要,我正在使用puppet-0.25.4-1.fc13.noarch.rpm和puppet-server-0.25.4-1.fc13.noarch.rpm.

附: undef适用于所有者,组和权限,但不适用于SELinux.如果分区已经安装,木偶抱怨:

puppetd[18052]: Failed to set SELinux context system_u:object_r:public_content_t:s0 on /mnt/sda3
puppetd[18052]: (/File[/mnt/sda3]/seluser) seluser changed 'unconfined_u' to 'system_u'
puppetd[18052]: Failed to set SELinux context unconfined_u:object_r:mnt_t:s0 on /mnt/sda3
puppetd[18052]: (/File[/mnt/sda3]/seltype) seltype changed 'public_content_t' to 'mnt_t'

已安装分区的权限是:

drwxr-xr-x. root root unconfined_u:object_r:public_content_t:s0 /mnt/sda3/

而puppet创建的挂载点的权限是:

drwxr-xr-x. root root system_u:object_r:mnt_t:s0       /mnt/sda3/

P.P.S.我已经为这种奇怪的行为报告了bug.

解决方法

您可以通过将其设置为undef来告诉Puppet不管理给定的元参数.
file { "${location}/${name}":
    ensure                  => directory,owner                   => undef,group                   => undef,mode                    => undef,selinux_ignore_defaults => true,}

在这种情况下,如果在安装之前目录不存在,它将被创建为作为puppetd启动的用户和组(可能是root:wheel)和默认的umask. Puppet不会关心创建时或任何后续运行时设置的内容.

或者,如果您想交换一点复杂性来保证,您可以使用自定义事实来确定活动挂载是什么,并使用switch语句来设置目录权限,具体取决于它是预安装还是后安装.

相关文章

查找全部容器的日志文件 $ sudo find /var/lib/docker/conta...
Linux日志文件中列属性的详细解析
在Linux系统中没有duf命令,如何有效地管理磁盘空间?
深入探讨EncryptPad在Linux操作系统中的功能和优势
原理和应用场景:Linux中ttyload工具的工作原理和实际用途
深度解析SELinux的三种策略类型