Ask Your Question
0

Puppet variables quest-guide help

asked 2015-02-18 16:56:03 -0600

n8_sirly gravatar image

Hi All,

Apologies if this was asked before, but I'm having an issue with the puppet quest "Variables".

On task 2 it wants you to copy and paste the following code into an init.pp file:

class web {
$doc_root = '/var/www/html/lvmguide'
$english = 'Hello world!'
$french = 'Bonjour le monde!'
file { "${doc_root}/hello.html":
ensure => 'present',
content => "<em>${english}</em>",
}
file { "${doc_root}/bonjour.html"}
ensure => 'present',
content => "<em>${french}</em>",
}
}

But if I run the validator on the code, it says it is imporerly coded. What I think happened is that there is an extra '}' on line 9 that should be a ':' . However if I fix the code, it then fails to apply with my test init.pp.

[root@learning /etc/puppetlabs/puppet/environments/production/modules/web]# puppet apply -e web/tests/init.pp
Error: Could not parse for environment production: Syntax error at '/' at line 1 on node learning.puppetlabs.vm
Error: Could not parse for environment production: Syntax error at '/' at line 1 on node learning.puppetlabs.vm

If I run puppet parser validate on both web/manifests/init.pp and web/tests/init.pp the files are valid. I am not sure what I'm missing, but I am wondering if someone can point in the right direction. I would be much appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-02-19 03:29:15 -0600

Akira01 gravatar image

updated 2015-02-19 03:31:26 -0600

Hi, Just try this. I use Geppetto for coding Puppet... a really cool tool :-) :

class web (
$doc_root = '/var/www/html/lvmguide',
$english = 'Hello world!',
$french = 'Bonjour le monde!',
)
{
file { "${doc_root}/hello.html":
ensure => 'present',
content => "<em>${english}</em>",
    }
file { "${doc_root}/bonjour.html":
ensure => 'present',
content => "<em>${french}</em>",
   }
}

The general form of a class definition is:

The class keyword

The name of the class

An optional set of parameters, which consists of:

An opening parenthesis

A comma-separated list of parameters, each of which consists of:

A new variable name, including the $ prefix

An optional equals (=) sign and default value (any data type)

An optional trailing comma after the last parameter

A closing parenthesis

edit flag offensive delete link more

Comments

Thanks for the response. It looks like I'm receiving the same error about "Error: Could not parse for environment production: Syntax error at '-' at line 1 on node learning.puppetlabs.vm" with your code. edit: fixed the error message

n8_sirly gravatar imagen8_sirly ( 2015-02-20 10:12:21 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-02-18 16:56:03 -0600

Seen: 335 times

Last updated: Feb 19 '15