Fork me on GitHub
Suzf  Blog

Tag Puppet

Puppet erb template

puppet templates follow the erb templating standard.

The puppet documentation contains an example of how to do a simple if statement.

<% if broadcast != "NONE" %>       
    broadcast <%= broadcast %>
<% end %>

To do an if/else statement, simply add <% else %>

<% if @someclass::someparameter != true %>
    bar = 42
<% else %>
    bar = 0
<% end %>

--  for dynamic content use: <%= %>
--  for another content use: <% %>
-- eg: <% if 1>2 %>

 

http://stackoverflow.com/questions/6932663/whats-wrong-with-my-simple-if-else

https://docs.puppetlabs.com/puppet/latest/reference/lang_template_erb.html

 

The Puppet Language Style Guide

Puppet Language Style Guide: Version 2.0.1Puppet: Version 3.7+

(Note: While the style guide maps to Puppet 3.7, many of its recommendations apply to Puppet 3.0.x and up.)

Puppet 将模块绘制成依赖关系图

依赖使关系迅速变得复杂,并且很容易结束循环依赖,(其中A依赖B,B又依赖A)这将引起
puppet编译错误并停止工作,幸运的是,puppet的图表选项可以很容易生成一个资源之间的依赖
关系图,它可以帮助我们解决这些问题。

Puppet之安装dashboard 成功版

Puppet Dasshboard是由支持Puppet开发的公司Puppetlabs创建的,是Ruby on Rails程序。可以作为一个ENC(外部节点分类器)以及一个报告工具,并且正在逐渐成为一个包含许多Puppet新功能的集成界面,例如审计和资源管 理功能。 Puppet Dashboard是一个Ruby on Rails程序,用于显示Puppet master和agent的相关信息。它允许你查看从一个或多个Puppet master汇总的图形和报告数据。它同时从一个或者多个Puppet master上收集来自于Puppet agent的资产数据(主机的Fact和其他信息)。最后,它能作为一个ENC来配置Puppet节点,并指定这些节点上的类和参数。

Puppet 自定义facter 简述

在使用puppet作为配置管理工具的同时,facter是一个非常有用的系统盘点工具,自定义fact可以让节点增加更多的标签。这个工具可以通过一些预先设定好变量定位一台主机,比如可 以通过变量lsbdistrelease便可以知道当前系统的版本号,通过osfamily便可以知道系统是RedHat还是SLES,还是其它等等。但 是这些预先设定好的变量毕竟有限,在整个自动化运维过程中,由于系统应用的多样性,更多需要通过应用的名称、角色的名称进行标示,这样就需要自定义一些 fact并赋值到每个节点上去,相当于给节点打上标签。

Puppet 之 Nginx 模块编写

搞puppet也有三几天了,一些概念还不是很清晰。很多时候实验未成功,都是概念没有理清楚、文档没有看全。别的就先不说了,先来安装一个nginx 来试一下吧。

FAQ_Puppet: 常见问题 【持续更新中】

Q1:最近测试3.7.1 的版本出现了一个问题:The package type's allow_virtual parameter will be changing its default value from false to true in a future release

A1:

[root@agent1 ~]# puppet --version
3.7.1

[root@agent1 ~]# puppet agent --test --server master.jeffery.com --noop
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent1.jeffery.com
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
(at /usr/lib/ruby/site_ruby/1.8/puppet/type/package.rb:430:in `default')
Info: Applying configuration version '1413249918'

Notice: Finished catalog run in 0.11 seconds

出现一个警告,但不影响执行的结果,有群友说是版本有问题,最终我也不知道是神码问题的。。

可以在服务器端的 pp文件中的package 中加入 :allow_virtual => false, 来解决出现的警告。

检查文件的正确性spacer.gif

测试

Q2:

puppet Error 400 on SERVER Permission denied

Error: /Stage[main]/Ssh::Config/File[/etc/ssh/sshd_config]: Could not evaluate: Error 400 on SERVER: Permission denied - /etc/puppet/modules/ssh/files/sshd_config Could not retrieve file metadata for puppet:///modules/ssh/sshd_config: Error 400 on SERVER: Permission denied - /etc/puppet/modules/ssh/files/sshd_config

A2: chmod -R ./ssh/files/*

Q3:

What causes the error “Could not retrieve catalog from remote server: execution expired” in Puppet

This can be caused when the load on the Puppet Master server is too high to send compiled catalogs to the agents.
Start by checking if any services are using all the available resources, or if the server is under-powered for the requests it is getting. If all agents run at the same time, edit the cron job that controls their run time to spread it out.
If all else fails, allowing the agents to take longer to receive the catalog may work. This can be done by adding the configtimeout setting to the puppet.conf file (/etc/puppet/puppet.conf) and increasing the value. It defaults to "2m", meaning two minutes.

Q4:

Error: Could not retrieve catalog from remote server: Connection refused - connect(2)
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
Error: Could not send report: Connection refused - connect(2)

此错误是没有启动puppet master服务 或是没有绑定主机名/DNS 未得到正确解析

[14:37:04][root@agent01 ~]$ cat /etc/hosts | grep 192
#192.168.9.10     master01.ocean.org   master01
#192.168.9.20     agent01.ocean.org    agent01

取消注释 再次执行 问题解决