1

状态

描述的是状态,而非步骤。

通过manifests描述状态,确保每个节点符合这个状态。

可读性

service {"ssh": ensure => running;}

资源

  • 种类:exec、mount、service、file、package、user、group、host
  • 提供者:RHEL、Centos、Ubuntu、Mac OS X、Windows

语法

基本的写法

type { "title":
  attribute => value,
  attribute => value
}

从BNF可以看出语法是比较简单的:

<exp> ::= <exp> <arithop> <exp>
        | <exp> <boolop> <exp>
        | <exp> <compop> <exp>
        | <exp> <matchop> <regex>
        | ! <exp>
        | - <exp>
        | "(" <exp> ")"
  `     | <rightvalue>

<arithop>   ::= "+" | "-" | "/" | "*" | "<<" | ">>"
<boolop>    ::= "and" | "or"
<compop>    ::= "==" | "!=" | ">" | ">=" | "<=" | "<"
<mathchop>  ::= "=~" | "!~"
<rightvalue>::= <variable> | <function-call> | <literals>
<literals>  ::= <float> | <integer> | <hex-integer> | \
                <octal-integer> | <quoted-string>
<regex>     ::= '/regex/'

模板是ERB语法

<%= @fact %>

<% if @ipaddress_eth0 != "NONE" %>
ServerName <%= @printserver %>
<% end %>

<% nameservers.each do |server| -%>
nameserver <%= server %>
<% end -%>

检查语法:

puppet parse validate mymanifest.pp

应用:

puppet apply mymanifest.pp

augeas将文件转化为对象,可以操作文件的一部分。

augeas { "sshd password authentication":
  context => "files/etc/ssh/sshd_config"
  changes => [
    "set PasswordAuthentication no"
  ],
  notify => Service["sshd"]
}

多个资源可以组合成class,子类可以覆盖父类的属性——子类使用大写开头的资源定义,覆盖父类中小写开头的同名资源定义。没有继承关系的class中的变量,通过$other::myvar访问。

filebuckets可以用来备份和恢复文件:

; puppet filebucket --local backup /etc/puppet/puppet.conf
/etc/puppet/puppet.conf: eb503235c23df33555800d2cc
; puppet filebucket --local restore /etc/puppet/puppet.conf \
 eb503235c23df33555800d2cc

weakish
24.6k 声望844 粉丝

a vigorously lazy deadbeat with matured immaturity


引用和评论

0 条评论