如何拆分木偶文件

Don*_*joe 1 puppet devops

只是想知道我是否有以下puppet文件,我想将它们分成单独的文件.我必须创建模块吗?我不能只包括它们吗?

node default {
  include mysql
}


class mysql {

  # Make sure MySQL is ...
  notify {"Mysql":}

  # installed
  package { 'mysql':
  require => Exec['apt-update'], # require 'apt-update' before installing
  ensure => installed,
  }

  # and running
  service { 'mysql':
    ensure => running,
    enable => true,
  }
}

...
Run Code Online (Sandbox Code Playgroud)

我只是想把mysql类拿出来放在单独的文件中.怎么做这个简单的事情?顺便说一句,我正在使用无主的木偶

编辑

很大的道歉,事实是我只使用没有流浪汉的傀儡.但由于我不是一个专家,当我的问题有一个修改,包括流浪汉我接受了它.对不起,请允许我修改我的问题

我可以在没有流浪汉的情况下进行分离吗?如果我必须如此.

谢谢

Fré*_*nri 5

您可以将您的mysql班级移动到自己的模块中

你最终会得到这样的东西

.
??? Vagrantfile
??? puppet
|   ??? manifests
|         ????? base.pp
|   ??? modules
|         ??? mysql
|               ??? manifests
|                     ????? init.pp
Run Code Online (Sandbox Code Playgroud)

Vagrantfile就像

Vagrant.configure("2") do |config|
    <make all your configuration here>
    config.vm.provision :puppet do |puppet|
      puppet.manifests_path = "puppet/manifests"
      puppet.manifest_file = "base.pp"
      puppet.module_path = "puppet/modules"
    end
  end

end
Run Code Online (Sandbox Code Playgroud)

base.pp文件只包含

node default {
  include mysql
}
Run Code Online (Sandbox Code Playgroud)

并且你的mysql/init.pp文件将包含mysql类本身

class mysql {

  # Make sure MySQL is ...
  notify {"Mysql":}

  # installed
  package { 'mysql':
  require => Exec['apt-update'], # require 'apt-update' before installing
  ensure => installed,
  }

  # and running
  service { 'mysql':
    ensure => running,
    enable => true,
  }
}
Run Code Online (Sandbox Code Playgroud)

在puppet中进行模块练习可能是一个好主意,但老实说,你更有可能使用现有模块而不是重新发明轮子:https://forge.puppet.com/puppetlabs/mysql/2.2.3将是一个好的模块使用