"Learn Puppet with me" 1.5 Puppet 3.7 using Hiera to define the configuration

Source: Internet
Author: User

1. Environmental preparedness

Os:centos 6.4

Turn off SELinux and iptables

Deployment Puppet: 1.0 Puppet 3.7 Department  

Install puppet Source: http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm


Complete Puppetmaster/agent deployment, certificate signing ...

Hiera is a lookup tool for Key/value configuration data that can be used to configure special node configuration data conveniently.



2. Using Hiera

a) Install Hiera

If you install puppet 3.7, you do not need to install Hiera again.

If you are installing version 2.7, you need to execute the following command.

Yum Install Hiera hiera-puppet-y


B) configuration Hiera.yaml

To view the path to a configuration file

Puppet Master--configprint hiera_config #默认在/etc/puppet/hiera.yaml


The Hiera configuration file must be in YAML hash format.

#一个参考的配置: Pay attention to each top-level configuration, before you must have a---: backends:-Yaml-json:yaml::d atadir:/etc/puppet/hieradata:json::d atadir:/et C/puppet/hieradata:hierarchy:-"%{::clientcert}"-"%{::custom_location}"-common# if the Hiera.yaml exists, but the inside is empty. Then its default configuration is as follows: ---: Backends:yaml:yaml::d atadir:/var/lib/hiera:hierarchy:common:logger:console


C) configuration parameters

#顶层配置:hierarchy   #必须是一个字符串或数组, each name represents a static or dynamic Data source    #动态数据是一个简单的  %{variable}  interpolation variables    #在层次结构中, sequentially checked, top-down .   #默认值是common:backend   #必须是一个字符串或数组, Each name represents an available Hiera backend   #内置的backend是yaml和json that can be added with additional backend as additional    #默认值是yaml #backend settings :yaml and :json:datadir      #可以在目录中找到数据源的文件, must be a string   # You can use the variable interpolation/etc/puppet/hieradata/%{::environment}   #默认值  /var/lib/hiera# configuration in the path hiera.yamlmkdir  /etc/puppet/hieradata/cat > /etc/puppet/hiera.yaml <<eof---: backends:  -  yaml:yaml:  :d atadir: /etc/puppet/hieradata:logger: console:hierarchy:  -   "%{operatingsystem}%{::operatingsystemmajrelease}"   -  "%{::osfamily}"   -  commoneof# Create a data file that will be matched by default: Use classes to introduce the base module cat > /etc/puppet/hieradata/common.yaml << EOF---classes:  - baseeof# created when osfamilyFiles that are matched to RedHat ... cat > /etc/puppet/hieradata/redhat.yaml <<eof---os: redhateof# Create files when OperatingSystem and operatingsystemmajrelease are matched: Cat > /etc/puppet/hieradata/centos6.yaml <<eof---os: centos os_type:   linux: true   unix: falseeof# Configuring SITE.PP Auto-Import class module ... cat > /etc/puppet/ Manifests/site.pp <<eofhiera_include (' classes ') eof# create a base module and print out the OS variable # you can use three function # Standard queries for lookup data Hiera   Get a value# merge query that matches the key hiera_array   get all the matching keys and then return their values to an array of # merge queries hiera_hash  similar arrays, Returns the structure of the hash. mkdir /etc/puppet/modules/base/manifestscat > /etc/puppet/modules/base/manifests/ init.pp <<eofclass base {   $test 1 = hiera (' OS ')    $test 2  = hiera_array (' OS ')    $test 3 = hiera_hash (' Os_type ')   notify {   "os1:  $test 1":}  notify {  "os2:  $test 2":}  notify&nbsp {  "os3:  $test 3[' Linux ']    $test 3[' Unix ']":}} eof# Restart Puppet master



3. Executing the puppet Agent

[[email protected] ~]# puppet agent --verbose --no-daemonizenotice:  starting puppet client version 3.7.3info: retrieving pluginfactsinfo:  retrieving plugininfo: caching catalog for agent1.dbsa.cninfo: applying  configuration version  ' 1417636182 ' notice: os3: linuxtrueunixfalse[' Linux ']    linuxtrueunixfalse[' UNIX ']notice: /stage[main]/base/notify[os3: linuxtrueunixfalse[' Linux '    linuxtrueunixfalse[' UNIX ']]/message: defined  ' message '  as  ' os3:  linuxtrueunixfalse[' Linux ']   linuxtrueunixfalse[' unix '] ' Notice: os1: centosnotice:  /Stage[main]/Base/Notify[OS1: CentOS]/message: defined  ' message '  as  ' os1:  CentOS ' notice: os2: centosredhatdefaultnotice: /stage[main]/base/notify[os2:  centosredhatdefault]/message: defined  ' mEssage '  as  ' Os2: centosredhatdefault ' notice: finished catalog run in  0.03 seconds^cnotice: caught int; calling stop[[email protected] ~]#  Facter operatingsystemcentos[[email protected] ~]# facter operatingsystemmajrelease6




This article is from the "Xiaofeng Moon" blog, make sure to keep this source http://kinda22.blog.51cto.com/2969503/1586495

"Learn Puppet with me" 1.5 Puppet 3.7 using Hiera to define the configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.