使用Chef在Ubuntu 12.04上设置ACL

4

我一直在尝试想出如何编写一份配方,以安装ACL软件包并启用它来重新挂载文件系统根目录:

  1. apt-get install acl
  2. 在fstab中的选项中添加“acl”
  3. mount -o remount /

我所尝试的配方是:

case node[:platform]
when "debian","ubuntu"
    package "acl" do
        action :install
    end

    mount "/" do
        options "acl"
        action [:remount, :enable]
    end
end

非常遗憾(但也不出所料)的是,Chef 不知道如何读取现有的 /etc/fstab 条目并为其添加 acl,而不改变其他任何内容,因此它正在清除挂载点上现有的选项。您有什么想法可以完成这个任务吗?

1个回答

4

我找到了一种使用Augeas的方法:

# Install ACL and remount the root volume with ACL enabled
case node[:platform]
when "debian","ubuntu"
    %w{acl augeas-tools}.each do |pkg|
        package pkg
    end

    execute "update_fstab" do
        command <<-EOF
            echo 'ins opt after /files/etc/fstab/*[file="/"]/opt[last()]
            set /files/etc/fstab/*[file="/"]/opt[last()] acl
            save' | augtool
            mount -o remount /
        EOF
        not_if "augtool match '/files/etc/fstab/*[file=\"/\"]/opt' | grep acl"
    end
end

我并不是很喜欢这个解决方案,但它似乎有效。不过,肯定有更好的方法,对吧?


我已经发布了一个包含您解决方案的菜谱书 https://supermarket.getchef.com/cookbooks/acl - Maks3w

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接