Introduction of the foreman architecture 10-hostgroup how to convert to local fact

Source: Internet
Author: User

0 Basic Learning Puppet Automation configuration Management Series documentation

On foreman, you can set up multiple host groups (hosts Groups) based on business logic, and you can add different nodes to a different host group, so that each time you operate "puppet run", you only need to search the search button for the corresponding host unit to find all the nodes contained in it. As shown

650) this.width=650; "src=" Http://kisspuppet.com/img/foreman10-1.png "alt=" Foreman Install "style=" margin:0px;padding:0 Px;height:auto;border:none; "/>foreman Installing

But, Foreman is currently in puppet run is very low, basically only one command can be run. So if you want to go through the MCO command on the shell terminal to the custom host Groups What should I do? The answer is to convert to Facter.

There are four ways of customizing Facter, as follows: http://kisspuppet.com/2014/03/30/puppet_learning_base10/

Here's a third way to convert the host group set up on foreman to each node's own facter

1. First create the host group

650) this.width=650; "src=" Http://kisspuppet.com/img/foreman10-2.png "alt=" Foreman Install "style=" margin:0px;padding:0 Px;height:auto;border:none; "/>Foreman installation

2. View the host group information of the node

In fact, the equivalent of a custom external variable, the variable is called HostGroup, the value of the node join the group name

650) this.width=650; "src=" Http://kisspuppet.com/img/foreman10-3.png "alt=" Foreman Install "style=" margin:0px;padding:0 Px;height:auto;border:none; "/>foreman Installing

650) this.width=650; "src=" Http://kisspuppet.com/img/foreman10-4.png "alt=" Foreman Install "style=" margin:0px;padding:0 Px;height:auto;border:none; "/>Foreman installation

3. Write a fact module

The function of the module is to ground the variable "HostGroup" on the foreman to the/etc/facter/facts.d/${hostname}.txt file of each node, which is the standard format of fact.

#模块结构 [[email protected] modules]# tree factfact├── files├── manifests│    ├── config.pp│   ├── fact.pp│   ├── init.pp│    └── params.pp└── templates    └── hostgroup.erb3  directories, 5 files# Module master configuration file init.pp[[email protected] modules]# cat fact/ Manifests/init.pp class fact {  tag ("Puppet_env")   require fact:: params   $hostgroup _erb =  $fact::p arams::hostgroup_erb  include fact::config   include fact::facter} #创建目录以及文件 [[email protected] modules]# cat fact/ manifests/config.pp class fact::config{  file {  '/etc/facter '  :     ensure  => directory,    owner   =>  ' Root ', &NBSP;&NBSP;&NBSP;&NBSP;GROUP&NBSP;&Nbsp; =>  ' root ',    mode    =>  ' 0644 ',   }  file {  '/ETC/FACTER/FACTS.D '  :    ensure  =>  directory,    owner   =>  ' Root ',     group    =>  ' root ',    mode    =>  ' 0644 ',     require => file['/etc/facter ']  }  file{  "/etc/ facter/facts.d/$hostname. txt ":    owner   => " root ",     group   =>  "Root",    mode    =>  0400,    content => template ($fact:: Hostgroup_erb),     require => file['/ETC/FACTER/FACTS.D '],  }} #定义变量 [[email protected]  modules]# cat fact/Manifests/params.pp class fact::p arams{   $hostgroup _erb =  ' Fact/hostgroup.erb '}# Define a fact template (reason can refer to http://kisspuppet.com/2013/11/10/mcollective-middleware/) [[Email protected] manifests] # cat fact.pp class fact::facter{file{"/etc/mcollective/facts.yaml":     owner    => root,    group    =>  root,    mode     => 0440,     loglevel => debug, # reduce noise in puppet reports     content  => inline_template (' <%= scope.to_hash.reject { |k,v|  k.to_s =~ /(uptime.*|path|timestamp|free|. *password.*|. *psk.*|. *key)/ }.to_yaml %> '),   } #设置文件模板 [[email protected] modules]# cat  Fact/templates/hostgroup.erb hostgroup=<%=&nbSP; @hostgroup  %> foreman_env=<%=  @foreman_env  %> 
4. Managing host groups and modules on foreman fact

First import the class, then the association in the host group, because the fact module is for all hosts, it is recommended to associate to a Level 1 host group, the joined nodes will automatically inherit. The effect after the association is completed is as follows

650) this.width=650; "src=" Http://kisspuppet.com/img/foreman10-5.png "alt=" Foreman Install "style=" margin:0px;padding:0 Px;height:auto;border:none; "/>Foreman installation

650) this.width=650; "src=" Http://kisspuppet.com/img/foreman10-6.png "alt=" Foreman Install "style=" margin:0px;padding:0 Px;height:auto;border:none; "/>Foreman installation

5. Perform "puppet run" operation on foreman on two nodes

650) this.width=650; "src=" Http://kisspuppet.com/img/foreman10-7.png "alt=" Foreman Install "style=" margin:0px;padding:0 Px;height:auto;border:none; "/>Foreman installation

6. See if facter information is generated
[Email protected] ~]# facter HOSTGROUPPRD [[email protected] ~]# Facter Hostgroupprd/kisspuppet
7, through the MCO command combined with fact filter view
[[Email protected] ~]# mco ping  -f hostgroup=prdforeman163.kisspuppet.com                 time=98.55 &NBSP;MS---- ping statistics ----1 replies max: 98.55 min: 98.55  avg: 98.55 [[email protected] ~]# mco ping  -f hostgroup=prd/ Kisspuppetpuppetmaster162.kisspuppet.com           time =94.14&NBSP;MS---- ping statistics ----1 replies max: 94.14 min: 94.14  avg: 94.14 [[email protected] ~]# mco puppet -v runonce -f  hostgroup=prd/kisspuppetdiscovering hosts using the mc method for 2  second (s)  .... 1 * [ ========================================================== ==> ] 1 / 1puppetmaster162.kisspuppet.com          :  ok    {:summary=>       "Started a Puppet  run using the  ' Puppet agent --test --color=false --splay --splaylimit  30 '  command '}---- rpc stats ----            Nodes: 1 / 1     Pass / Fail: 1  / 0      start time: thu dec 18 15:13:09 + 0800 2014  discovery time: 2004.07ms      agent  Time: 85.19ms      total time: 2089.26ms

Note: The above approach only provides a way of thinking, more ways also need to be based on the actual environment and change, in short, fact is very powerful, see how you use.


This article is from the "www.kisspuppet.com" blog, make sure to keep this source http://dreamfire.blog.51cto.com/418026/1591390

Introduction of the foreman architecture 10-hostgroup how to convert to local fact

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.