2017-02-25 15 views
1

問題

我已經在不同的環境清單分割一個木偶成兩個清單,每一個,並且在所述第二環境中的清單不似乎能夠引用任何模塊。我很確定發生這種情況是因爲我做錯了什麼,但我無法弄清楚。移到定製木偶模塊到一個單獨的環境,現在不能加載任何依賴

[email protected]:~$ puppet --version 
4.9.2 

摘要

我正在學習用木偶。我有三個自定義模塊,我已經寫得很完美。我想將我的過程分成兩步:

  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, 
} 

運行木偶艙單

隨着封隔器,我有一個封隔器的配置是建立一個清新的形象與/puupet-env/base/manifests/site.pp,並建立與/puupet-env/deploy/manifests/site.pp該圖像上的第二配置。

隨着流浪,我只是在我的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 

錯誤消息

我得到同樣的錯誤消息,如果我在流浪或與帕克一個數字海洋箱運行此。

==> 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。

建造者。第

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", 
    } 
} 
+0

你可以確認你正在使用的木偶版本添加您的builder.pp –

+0

的內容我正在使用4.9.2。 將添加builder.pp到我的文章。 – terrarum

+0

我已將builder.pp添加到我的問題中。 – terrarum

回答

1

確保在你的傀儡文件中添加主nginx的類

class { 'nginx': } 

的定義之前,你可以評估nginx::resource::vhost

+0

Ahhhhh,就是這樣做的。我以爲,因爲它已經被定義,只要它在系統上,並被我的第二個清單發現。非常感謝你! – terrarum

+1

不一定,在你的情況下,你真的兩次運行木偶作爲兩個不同的提供者,所以它無法從第一個清單中找到 –