• chef 配置之 Templates


    chef template 简单例子

    cat nginx_config.rb

    .....
    template '/etc/nginx/nginx.conf' do source 'nginx.conf.erb' owner 'root' group 'root' mode '0644' end
    .......
    /etc/nginx/nginx.conf 目标文件位置
    nginx.conf.erb 模板文件

    puppet 是这样表达的

    file{"nginx.conf":
    ensure => present,
    mode => 644,owner => root,group => root,
    path => "/etc/nginx/nginx.conf",
    content=> template("nginx/nginx.conf.erb"),
    require=> Package["nginx"],
    }

    简单对比下方便理解

    chef template的resource

    template 'name' do
      atomic_update              TrueClass, FalseClass
      backup                     FalseClass, Integer
      cookbook                   String
      force_unlink               TrueClass, FalseClass
      group                      String, Integer
      helper(:method)            Method { String } # see Helpers below
      helpers(module)            Module # see Helpers below
      inherits                   TrueClass, FalseClass
      local                      TrueClass, FalseClass
      manage_symlink_source      TrueClass, FalseClass, NilClass
      mode                       String, Integer
      notifies                   # see description
      owner                      String, Integer
      path                       String # defaults to 'name' if not specified
      provider                   Chef::Provider::File::Template
      rights                     Hash
      sensitive                  TrueClass, FalseClass
      source                     String, Array
      subscribes                 # see description
      variables                  Hash
      verify                     String, Block
      action                     Symbol # defaults to :create if not specified
    end
    • template is the resource
    • name is the name of the resource block, typically the path to the location in which a file is created and also the name of the file to be managed. For example: /var/www/html/index.html, where /var/www/html/ is the fully qualified path to the location and index.html is the name of the file
    • source is the template file that will be used to create the file on the node, for example: index.html.erb; the template file is located in the /templates directory of a cookbook
    • :action identifies the steps the chef-client will take to bring the node into the desired state
    • atomic_updatebackupcookbookforce_unlinkgrouphelperhelpersinheritslocalmanage_symlink_sourcemodeowner,pathproviderrightssensitivesourcevariables, and verify are properties of this resource, with the Ruby type shown. See “Properties” section below for more information about all of the properties that may be used with this resource.
  • 相关阅读:
    Beetle在TCP通讯中使用协议分析器和自定义协议对象
    Beetle在TCP通讯中使用AMF3协议和Flash通讯
    发布一个TCP 吞吐性能测试小工具
    替书仙澄清一些东西,并且对无知的人谈谈网络追踪
    2006年4月1日测彩研究
    构建工具研究:该死的Maven的j2me构建
    2006年4月2日测彩研究
    Eclipse的插件代码折叠
    JAVA这堆IDE........无言
    假如人生不曾相遇(转)
  • 原文地址:https://www.cnblogs.com/iamdevops/p/5624704.html
Copyright © 2020-2023  润新知