puppetlabs/puppetlabs-nginx — pull request #35 by blakesmith (2012-12-26 23:31:51+00:00)
Title: Fix template has_variable? check per: http://docs.puppetlabs.com/guides/templating.html

Hello there!

I was trying to use this nginx module with vagrant, with the following config:

```puppet
node default {
class { 'nginx': }
nginx::resource::vhost { 'blakesmith.me':
ensure => present,
www_root => '/vagrant',
}
}
```

I got the following stacktrace:

```
[default] Attempting graceful shutdown of VM...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- v-root: /vagrant
[default] -- manifests: /tmp/vagrant-puppet/manifests
[default] -- v-pp-m0: /tmp/vagrant-puppet/modules-0
[default] Running provisioner: Vagrant::Provisioners::Puppet...
[default] Running Puppet with /tmp/vagrant-puppet/manifests/default.pp...
stdin: is not a tty
Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaults
Error: Failed to parse template nginx/vhost/vhost_location_directory.erb:
Filepath: /tmp/vagrant-puppet/modules-0/nginx/templates/vhost/vhost_location_directory.erb
Line: 7
Detail: undefined method `each' for :undef:Symbol
at /tmp/vagrant-puppet/modules-0/nginx/manifests/resource/location.pp:88 on node vagrant-ubuntu.vagrantup.com
Error: Failed to parse template nginx/vhost/vhost_location_directory.erb:
Filepath: /tmp/vagrant-puppet/modules-0/nginx/templates/vhost/vhost_location_directory.erb
Line: 7
Detail: undefined method `each' for :undef:Symbol
at /tmp/vagrant-puppet/modules-0/nginx/manifests/resource/location.pp:88 on node vagrant-ubuntu.vagrantup.com
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

cd /tmp/vagrant-puppet/manifests && puppet apply --modulepath '/tmp/vagrant-puppet/modules-0' /tmp/vagrant-puppet/manifests/default.pp
```

Digging in a little bit, it looks like the `templates/vhost/vhost_location_directory.erb` template uses a `has_variable?` check that's returning true, even though I didn't specify a `try_files` array. I stumbled on the [template guide](http://docs.puppetlabs.com/guides/templating.html) that says to use instance variables (@try_files) instead. This change fixes the stacktrace when I don't specify try_files and writes it out correctly when I do.

I'm new to Puppet, so I wasn't sure if I'm doing something wrong here, or what the correct fix is. Switching to an instance variable here seems to violate the style of the rest of the templates. What do you think?

Feedback appreciated!

Blake

Facter output:

```
architecture => amd64
domain => vagrantup.com
facterversion => 1.6.13
fqdn => vagrant-ubuntu.vagrantup.com
hardwareisa => x86_64
hardwaremodel => x86_64
hostname => vagrant-ubuntu
id => vagrant
interfaces => eth0,lo
ipaddress => 10.0.2.15
ipaddress_eth0 => 10.0.2.15
ipaddress_lo => 127.0.0.1
is_virtual => true
kernel => Linux
kernelmajversion => 3.2
kernelrelease => 3.2.0-32-generic
kernelversion => 3.2.0
lsbdistcodename => precise
lsbdistdescription => Ubuntu 12.04.1 LTS
lsbdistid => Ubuntu
lsbdistrelease => 12.04
lsbmajdistrelease => 12
macaddress => 08:00:27:db:0d:06
macaddress_eth0 => 08:00:27:db:0d:06
memoryfree => 1.87 GB
memorysize => 1.96 GB
memorytotal => 1.96 GB
netmask => 255.255.255.0
netmask_eth0 => 255.255.255.0
netmask_lo => 255.0.0.0
network_eth0 => 10.0.2.0
network_lo => 127.0.0.0
operatingsystem => Ubuntu
operatingsystemrelease => 12.04
osfamily => Debian
path => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
physicalprocessorcount => 1
processor0 => Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz
processor1 => Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz
processorcount => 2
ps => ps -ef
puppetversion => 3.0.0
rubysitedir => /usr/local/lib/site_ruby/1.8
rubyversion => 1.8.7
selinux => false
sshdsakey => AAAAB3NzaC1kc3MAAACBALa3US4YT6Rv2kNnjJrkT7jmQOmQquxCvGOJ96QKSfA5ZRm/+9Wje43unG3oMWKiSYbl+9HTfXKodbUvOyoO6jwez1gNIyWsz3pLe17IyE/vBCn8tVqAvUv2uB7IFCELxdfgjpjB8wJccxaRzwAQBU3xJ0+nD+9ZckLmkVps6lgvAAAAFQCgzhnQZhHbsAKrfMuiNhow9sFkQQAAAIAXD5xVI5kEXhOLi0OU5a+Zb/KEGVsZtha0NNwgQeyyrkbdyjAoOebNYfm4Yt4r/IE5VwVoM60KEmvppm0Erc3stYSTCUZns91eOda2ggX2ZqCWJoKQpcaCJYwu3TSxJdSMMscuGLOhP6aP0ErgkGgPNsCy7Q5BQilb8JAMs0UemwAAAIABO2uWTPdhZf3nuiaZ82QcNnNIhqBkd1tBjTrxCqVD8raNd8NNi2cXrCtCubwd3c5tS6AOcssrlwXcAX9bMQF6lj9u3B1jKU4Zm24WFjv+UDEIEhcqlJLplIlJBlv+ddrmV7zBKXdkkRMzE/ybNVwdN2ytgPdHXcS+nnc2adbTsQ==
sshecdsakey => AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBE5Ldzco+hpb96LHf539kejw6mB5wokW1gw6lpakSkP3TFEl6kIw3IQ1GXclRJlxCTgYiQpy1MAKEfevD2dUcxI=
sshrsakey => AAAAB3NzaC1yc2EAAAADAQABAAABAQDMcC8PPZjVdNx5bkq49lXuEBqnvejjijARAmi+ErNYGRabk5G4MxtF8aIq/OIIitybgTcVsvROzi7WB/NKaFCFeFOl/bFVH3Y0mAPsOHgeW/DrfcGzXG41Pow9O61oDEeISlao4+xTGyFotAnMtW4ZRX9QdCzesJrNWVCZUY2Z+xwxC7lEBsR3z+IaR1YlQE5ZzI0nwgo4ukhWiIFWg4QmQgPftAIWWvgDNpCiHPEREj1HJKs+KwdYBPDkTyLSnBKISV3/o8FnBXCgVG0zZOt01kzd+NijDRex4677whXGCk6KbxKymTnCL++q2qdjo1NZj1Mu5675SwHCQe273GHf
swapfree => 2.00 GB
swapsize => 2.00 GB
timezone => BRST
uniqueid => 007f0101
uptime => 0:02 hours
uptime_days => 0
uptime_hours => 0
uptime_seconds => 143
virtual => virtualbox
```