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

时间:2017-02-25 20:17:13

标签: vagrant puppet packer

问题

我已将Puppet清单拆分为两个清单,每个清单位于不同的环境中,而第二个环境中的清单似乎无法引用任何模块。我很确定这种情况正在发生,因为我做错了什么,但我无法解决问题。

ubuntu@vagranttest:~$ puppet --version
4.9.2

摘要

我正在学习使用Puppet。我已经编写了三个自定义模块,这些模块都完美无缺。我想将我的流程分为两个步骤:

  1. 一个Puppet清单,它构建了一个安装了所有依赖项的映像。
  2. 安装我的项目的第二个,使用以前构建的图像作为基础。此步骤取决于voxpupuli/nginx
  3. 这样,每当我添加要在此框中运行的新项目时,我都不必再次安装所有依赖项。

    我将引用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,
    }
    

    运行Puppet清单

    使用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",
      }
    }
    

1 个答案:

答案 0 :(得分:1)

确保添加主nginx类的定义

class { 'nginx': }
在您评估nginx::resource::vhost

之前,在您的puppet文件中