puppet笔记

状态

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

通过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可以看出语法是比较简单的:

 ::=   
        |   
        |   
        |   
        | ! 
        | - 
        | "("  ")"
  `     | 

   ::= "+" | "-" | "/" | "*" | "<<" | ">>"
    ::= "and" | "or"
    ::= "==" | "!=" | ">" | ">=" | "<=" | "<"
  ::= "=~" | "!~"
::=  |  | 
  ::=  |  |  | \
                 | 
     ::= '/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

你可能感兴趣的:(puppet)