How can I change a file with Chef?

后端 未结 4 1061
闹比i
闹比i 2020-11-29 04:24

I have 7 files and 1 war. I need to change values when I deploy them. I have this:

##usuario
#alfresco.user=*****
alfresco.user=********
##pass 
#alfresco.p         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 04:50

    Here is an example of how you can use Chef to uncomment a line in a configuration file. The ruby_block is protected with a ::File::grep. The test for Debian is just for fun.

    pam_config = "/etc/pam.d/su"
    commented_limits = /^#\s+(session\s+\w+\s+pam_limits\.so)\b/m
    
    ruby_block "add pam_limits to su" do
      block do
        sed = Chef::Util::FileEdit.new(pam_config)
        sed.search_file_replace(commented_limits, '\1')
        sed.write_file
      end
      only_if { ::File.readlines(pam_config).grep(commented_limits).any? }
    end if platform_family?('debian')
    

提交回复
热议问题