将自定义 Puppet 模块移至单独的环境,它现在无法加载任何依赖项

Moved custom Puppet module to a separate environment, it now cannot load any dependencies

问题

我将一个 Puppet 清单分成两个清单,每个清单在不同的环境中,第二个环境中的清单似乎无法引用任何模块。我很确定这是因为我做错了什么,但我不知道是什么。

ubuntu@vagranttest:~$ puppet --version
4.9.2

总结

我正在学习使用 Puppet。我编写了三个自定义模块,它们都运行良好。我想将我的过程分为两个步骤:

  1. 一个 Puppet 清单,它构建了一个安装了我所有依赖项的图像。
  2. 第二次安装我的项目,使用之前构建的图像作为基础。这一步取决于voxpupuli/nginx.

这样一来,每当我在此框中添加新项目 运行 时,我就不必再次安装所有依赖项。

我将引用 voxpupuli/nginx 的自定义模块移到了一个单独的 Puppet 环境中,现在它似乎完全不了解 nginx 模块是什么。

重构前

/puupet-env/dev/manifests/site.pp:

$repoPath = "/var/repos"
$sitePath = "/var/www"

class { 'userconfig': }

class {'dependencies':
  require => Class['userconfig'],
  repoPath => $repoPath,
  sitePath => $sitePath,
}

class { 'sitebuilder':
  repoPath => $repoPath,
  sitePath => $sitePath,
}

重构后

/puupet-env/base/manifests/site.pp:

$repoPath = "/var/repos"
$sitePath = "/var/www"

class { 'userconfig': }

class {'dependencies':
  require => Class['userconfig'],
  repoPath => $repoPath,
  sitePath => $sitePath,
}

/puupet-env/deploy/manifests/site.pp:

$repoPath = "/var/repos"
$sitePath = "/var/www"

class { 'sitebuilder':
  repoPath => $repoPath,
  sitePath => $sitePath,
}

运行 人偶清单

使用 Packer,我有一个打包器配置,它使用 /puupet-env/base/manifests/site.pp 构建一个新图像,第二个配置使用 /puupet-env/deploy/manifests/site.pp.

在该图像之上构建

对于 Vagrant,我只是在我的 Vagrantfile 中做了这个:

config.vm.define "dev", primary:true do |dev|
  config.vm.provision "shell", path: "provision.sh"

config.vm.provision "puppet" do |puppet|
  puppet.environment_path = "puppet-env"
  puppet.environment = "base"
  puppet.module_path = "modules"
end

config.vm.provision "puppet" do |puppet|
  puppet.environment_path = "puppet-env"
  puppet.environment = "deploy"
  puppet.module_path = "modules"
end

错误信息

如果我 运行 在 Vagrant 或带有 Packer 的 Digital Ocean 盒子上执行此操作,我会收到相同的错误消息。

==> dev: Warning: Unknown variable: '::nginx::config::spdy'. at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:219:35
==> dev: Warning: Unknown variable: '::nginx::config::http2'. at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:220:35
==> dev: Warning: Unknown variable: '::nginx::config::proxy_read_timeout'. at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:223:35
==> dev: Warning: Unknown variable: '::nginx::config::proxy_connect_timeout'. at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:224:35
==> dev: Warning: Unknown variable: '::nginx::config::proxy_set_header'. at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:225:35
==> dev: Warning: Unknown variable: '::nginx::config::proxy_hide_header'. at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:226:35
==> dev: Warning: Unknown variable: '::nginx::config::conf_dir'. at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:236:38
==> dev: Warning: Unknown variable: 'nginx::config::conf_dir'. at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:239:38
==> dev: Warning: Unknown variable: '::nginx::config::global_owner'. at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:283:35
==> dev: Warning: Unknown variable: '::nginx::config::global_group'. at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:284:35
==> dev: Warning: Unknown variable: '::nginx::config::global_mode'. at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:285:35
==> dev: Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, "" is not an Array.  
It looks to be a String at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/nginx/manifests/resource/vhost.pp:387:3  at /tmp/vagrant-puppet/modules-1cc77f85ff62eba00eccf0589f6e3b98/sitebuilder/manifests/builder.pp:18 on node vagranttest

谁能告诉我我做错了什么?我觉得这是因为我对 Puppet 不了解。

builder.pp

define sitebuilder::builder (
  $domain,
  $port,
  $sitePath,
  $repoPath,
  $remoteUrl,
  $location = false,
  $command = "npm start",
) {

  if $location {
    # Create location.
    nginx::resource::location{ $domain:
      proxy => "http://localhost:$port/",
      vhost => $location
    }
  }
  else {
    # Create vhost file.
    nginx::resource::vhost { $domain:
      listen_port => 80,
      proxy => "http://localhost:$port/" ,
    }

  }

  # Set up git to receive a push.
  githook::githook { $title:
    repoPath => $repoPath,
    repoName => $title,
    sitePath => $sitePath,
    command => $command,
    remoteUrl => $remoteUrl
  }

  # Create .env file.
  file { "/var/www/$title/.env":
    owner => 'helm108',
    ensure  => present,
    content => template('sitebuilder/env.erb'),
    require => Githook::Githook[$title],
  }

  # Create manual pull file.
  file_line { "Append update_repos.sh for $title":
    path => '/update_repos.sh',
    line => "cd $repoPath/$title && git fetch origin && git --work-tree=${sitePath}/${title} --git-dir=${repoPath}/${title} checkout -f master",
  }
}

确保添加主nginx的定义class

class { 'nginx': }

在你可以评估之前在你的人偶文件中 nginx::resource::vhost