迁移到木偶4.5.2

我们正在迁移到更高版本的puppet。

新版本:

# puppet --version 4.5.2 

现有版本:

 #puppet-3.8.7 

我们现有的site.pp如下:

 #A default site.pp to do a quick test run import "../classes/*" import "../nodes/*" file { 'testfile': path => '/home/test/testfile', ensure => present, mode => 0755, content => "A test file to check a different manifestdir" , } Exec { path => ["/bin" , "/sbini/", "/usr/bin" , "/usr/sbin/"] } 

现在,因为我们正在迁移到Puppet 4 ,我认为下面的导入function,包括多个pp文件不会在Puppet 4这里工作

 import "../classes/*" import "../nodes/*" 

如果我没有错,那么我可以将类和节点目录下的所有清单复制到下面的清单目录中

 /apps/puppetlabs/code/environments/production/manifests/site.pp 

请build议如何将清单更新到Puppet的更高版本,或者没有兼容性问题?

如果我没有错,那么我可以将类和节点目录下的所有清单复制到下面的清单目录中

是的,清单目录将被recursion地导入 ,所以这是最好的事情。

请build议如何将清单更新到Puppet的更高版本,或者没有兼容性问题?

有很多微妙的变化,所以用未来的parsing器( --parser future )testing你的Puppet 3上的清单,看看它们的工作效果如何。

从Puppet 3.x开始到4.x:获取升级就绪 ,发行说明和Puppet 3.8 deprecations 。

以下是我必须执行从Puppet代码迁移到Puppet 4的更改。

  • 使用导入function已被弃用。

木偶3代码:

我的site.pp使用导入函数调用其他清单,如下所示

  import "../classes/*" import "../nodes/*" 

木偶4代码:

根据“puppet config print manifest”指定的复制节点和类目录来清单目录

  # puppet config print manifest /etc/puppetlabs/code/environments/production/manifests # ls /etc/puppetlabs/code/environments/production/manifests classes nodes 

在我的情况下没有要求site.pp ,因为我们有多个节点的体现。 将类和节点放入清单目录将导致puppetrecursion地读取每个节点清单节点

  • 编写Puppet模板的语法更改

    木偶3代码:

    <%= ipaddress %> dev.example.com

    在Puppet 4上应用时出现以下错误

    Call, Failed to parse template /etc/puppet/templates/Node-002/hosts.erb: Filepath: /etc/puppet/templates/Node-002/hosts.erb: Line: 1 Detail: undefined local variable or method 'ipaddress' for #<Puppet::Parser::TemplateWrapper:0x007ffa98fb55c8>

    木偶4代码:

更新了代码如下,之后清单得到应用罚款
<%= @ipaddress %> node-002.example.com

– 数字属性值的表示

木偶3代码:

  ` file { "/etc/sudoers": path => "/etc/sudoers", ... mode => 440, } ` 

这是与下面的错误失败

  `Error: Failed to apply catalog: Parameter mode failed on File[/etc/sudoers]: The file mode specification must be a string, not 'Fixnum' at /etc/puppetlabs/code/environments/production/manifests/classes/user_default.pp:7` 

木偶4代码:修复是把模式值在引号内

  `file { "/etc/sudoers": path => "/etc/sudoers", ... mode => "440", } ` 

这些是我在移植到木偶4时遇到的主要问题。 之后,迁移顺利。