ruby 加入puppet_agent ot puppet_master ruby​​ script = version 1.0

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 加入puppet_agent ot puppet_master ruby​​ script = version 1.0相关的知识,希望对你有一定的参考价值。

#!/usr/bin/ruby -w
require 'erb'

  @puppet_server    = 'foreman.linux.com'
  @puppet_server_ip = '192.168.1.199'

  @p_m_regex = Regexp.new @puppet_server

  @conf = <<CONF_FILE
[main]
server= <%= @puppet_server %>
environment=production
runinterval= 1h
CONF_FILE

#########################################

def hosts_file
  match = File.read('/etc/hosts').split("\s").find_all {|line| line.to_s.downcase =~ @p_m_regex}
  if match.include?(@puppet_server)
    print "
=======================================================
  #{@puppet_server} is Already has entry in Hosts file
=======================================================
"
  else
    File.open('/etc/hosts', 'a') {|file| file.write "#{@puppet_server_ip}  #{@puppet_server}  #{@puppet_server.split('.')[0]}\n"}
    puts "
===========================================
    Puppet Master added to Hosts file
==========================================="
  end
end

def install_puppet_agent
  if(system("rpm -qa | grep puppet-agent"))
    puts "
===========================================
    Puppet Agent is Already Installed.
===========================================
    "
  else
    puts "
===========================================
    Installing Puppet Agent...
===========================================
    "
    system("rpm -ivh https://yum.puppetlabs.com/puppet5/puppet-release-el-7.noarch.rpm")
    system("yum -y install puppet && /opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true")
    if $?.exitstatus  != 0
      puts "
===========================================
     Unable to Install Puppet Agent!
===========================================
      "
    else $?.exitstatus = 0
    puts "
==================================================
    Puppet Agent has been Installed Successfully.
==================================================
    "
    end
  end
end

def puppet_conf
  erb = ERB.new(@conf).result(binding)
  File.open('/etc/puppetlabs/puppet/puppet.conf', 'w+').puts erb
  puts "
===============================================
    Configuration file Updated Successfully.
===============================================
  "
end

hosts_file
install_puppet_agent
puppet_conf

以上是关于ruby 加入puppet_agent ot puppet_master ruby​​ script = version 1.0的主要内容,如果未能解决你的问题,请参考以下文章

Ruby 文件的输入与输出

Ruby:带有 JSON 正文的 PUT 请求?

Ruby / Rails超时与线程 - 如何等待一段时间然后重新加入

Ruby on rails 协会 - 用户(设计)在注册和登录后可以“创建团队”或“加入团队”

Ruby Active Record加入并包括为count生成不同的sql

ruby Rspec+jenkins+allure持续集成