terrarum
terrarum

Reputation: 95

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

Problem

I've split a Puppet manifest into two manifests, each in a different environment, and the manifest in the second environment doesn't seem to be able to reference any modules. I'm pretty sure this is happening because I'm doing something wrong, but I can't work out what.

ubuntu@vagranttest:~$ puppet --version
4.9.2

Summary

I'm learning to use Puppet. I have three custom modules I've written that have all been working perfectly. I wanted to split my process into two steps:

  1. One Puppet manifest that builds an image with all my dependencies installed.
  2. A second that installs my projects, using the previously built image as a base. This step depends on voxpupuli/nginx.

That way I whenever I add new projects to be run on this box I don't have to install all of the dependencies again.

I moved my custom module which references voxpupuli/nginx to a separate Puppet environment and now it seems like it's lost all knowledge of what the nginx module is.

Before Refactor

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

After Refactor

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

Running Puppet Manifests

With Packer, I have one packer config that builds a fresh image with /puupet-env/base/manifests/site.pp, and a second config that builds on top of that image with /puupet-env/deploy/manifests/site.pp.

With Vagrant, I just did this in my 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

Error Message

I get the same error message if I run this on Vagrant or on a Digital Ocean box with Packer.

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

Can anyone tell me what I'm doing wrong? I feel like this is happening because I don't understand something about 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",
  }
}

Upvotes: 1

Views: 218

Answers (1)

Frederic Henri
Frederic Henri

Reputation: 53733

Make sure to add the definition of the main nginx class

class { 'nginx': }

in your puppet file before your can evaluate nginx::resource::vhost

Upvotes: 1

Related Questions