Re: [Puppet Users] Why IF-ELSE not work?

2013-02-14 Thread Brian Lalor
Import is like a #include in C: it's essentially a preprocessor directive and 
is evaluated before the if/ else. 

http://docs.puppetlabs.com/puppet/2.7/reference/lang_import.html

--
Brian Lalor
bla...@bravo5.org

On Feb 14, 2013, at 1:17 AM, Евгений Верещагин e.verescha...@gmail.com wrote:

 I try include different .pp for my systems. site.pp like:
 
 if $operatingsystem == 'debian' {
   import '../my/os/linux/debian.pp'
 }
 elsif $operatingsystem == 'windows' {
   import '../my/os/windows/windows.pp'
 }
 else {
   import '../my/os/default/default.pp'
 }
 
 and I try CASE:
 
 case $operatingsystem {
redhat: { import '../my/os/linux/redhat.pp' }
centos: { import '../my/os/linux/centos.pp' }
windows: { import '../my/os/windows/windows.pp' } 
default: { import '../my/os/default/default.pp' }
 }
 
 Why it didn't work? If I run puppet-agent, it read all pp-files and crash on 
 windows-parameters on Linux or on linux-parameters on Windows. What I do 
 incorrect?
 -- 
 You received this message because you are subscribed to the Google Groups 
 Puppet Users group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to puppet-users+unsubscr...@googlegroups.com.
 To post to this group, send email to puppet-users@googlegroups.com.
 Visit this group at http://groups.google.com/group/puppet-users?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  

-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Puppet Users] Why IF-ELSE not work?

2013-02-14 Thread Felix Frank
Hi,

import is largely deprecated for most uses. I haven't really used it
after Puppet 0.25.

What I learned back then was that the parser would honor all import
statements it would find. I believe that the if statements cannot be
validated until after the parsing stage, so they won't hinder importing.

Instead of relying on import based construct, make sure all your
resources are organized in trees of classes, and that each platform only
*includes* its appropriate tree root.

HTH,
Felix

On 02/14/2013 07:17 AM, Евгений Верещагин wrote:
 I try include different .pp for my systems. site.pp like:
 
 if $operatingsystem == 'debian' {
   import '../my/os/linux/debian.pp'
 }
 elsif $operatingsystem == 'windows' {
   import '../my/os/windows/windows.pp'
 }
 else {
   import '../my/os/default/default.pp'
 }
 
 and I try CASE:
 
 case $operatingsystem {
redhat: { import '../my/os/linux/redhat.pp' }
centos: { import '../my/os/linux/centos.pp' }
windows: { import '../my/os/windows/windows.pp' } 
default: { import '../my/os/default/default.pp' }
 }
 
 Why it didn't work? If I run puppet-agent, it read all pp-files and
 crash on windows-parameters on Linux or on linux-parameters on Windows.
 What I do incorrect?

-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Puppet Users] Why IF-ELSE not work?

2013-02-14 Thread jcbollinger


On Thursday, February 14, 2013 5:55:35 AM UTC-6, blalor wrote:

 Import is like a #include in C: it's essentially a preprocessor directive 
 and is evaluated before the if/ else. 

 http://docs.puppetlabs.com/puppet/2.7/reference/lang_import.html



But also, as I just remarked in another thread, 'import' causes the 
specified manifest to be parsed as a standalone manifest file.  That's 
decidedly *un*like cpp's '#include'.  As a result, it is misleading to put 
an 'import' anywhere other than at top scope.  If you are going to insist 
on using 'import', then at least do yourself the favor of putting all your 
'import' lines at the very beginning of the manifest.


John

-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Puppet Users] Why IF-ELSE not work?

2013-02-14 Thread Евгений Верещагин
I want call diffrent manifest files for diffrent rules and systems. I think 
that write all rules in one file is not good idea :-)

четверг, 14 февраля 2013 г., 18:41:33 UTC+4 пользователь jcbollinger 
написал:



 On Thursday, February 14, 2013 5:55:35 AM UTC-6, blalor wrote:

 Import is like a #include in C: it's essentially a preprocessor directive 
 and is evaluated before the if/ else. 

 http://docs.puppetlabs.com/puppet/2.7/reference/lang_import.html



 But also, as I just remarked in another thread, 'import' causes the 
 specified manifest to be parsed as a standalone manifest file.  That's 
 decidedly *un*like cpp's '#include'.  As a result, it is misleading to 
 put an 'import' anywhere other than at top scope.  If you are going to 
 insist on using 'import', then at least do yourself the favor of putting 
 all your 'import' lines at the very beginning of the manifest.


 John



-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Puppet Users] Why IF-ELSE not work?

2013-02-14 Thread jcbollinger


On Thursday, February 14, 2013 11:31:54 AM UTC-6, Евгений Верещагин wrote:

 I want call diffrent manifest files for diffrent rules and systems. I 
 think that write all rules in one file is not good idea :-)



No one suggested that you should put everything on one file.  Nevertheless, 
you cannot call a manifest in the sense of a function.  Puppet DSL is not 
a scripting language, and manifests are not executable in any meaningful 
sense.  You need to get your head around that (among other things) to 
become proficient with Puppet.

Instead of thinking in terms of files, you should be working on modeling 
your target systems via classes.  If you lay out your classes in the 
recommended (and autoloader-supported) way, then the distinction will be 
thin, as you will have only one class or definition per file.  The point, 
however, is to harmonize your mental model with the way Puppet actually 
works.

In your case, you might write site.pp like this:

manifests/site.pp
---

# Prefer to avoid top-scope declarations other than node blocks,
# class definitions, and defined-type definitions
node default {
  # prefer to put logic in classes, keeping node blocks simple
  include 'site'
}

with a module site defined by:


modules/site/manifests/init.pp:
---

class site {
  case $operatingsystem {
redhat: { include 'site::redhat' }
centos: { include 'site::centos' }
windows: { include 'site::windows' }
default: { include 'site::default' }
  }
}


modules/site/manifests/redhat.pp
---

class site::redhat {
  # declarations for redhat systems
}


And similar classes site::centos, site::windows, and site::default as well, 
each in its own file.


John

-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[Puppet Users] Why IF-ELSE not work?

2013-02-13 Thread Евгений Верещагин
I try include different .pp for my systems. site.pp like:

if $operatingsystem == 'debian' {
  import '../my/os/linux/debian.pp'
}
elsif $operatingsystem == 'windows' {
  import '../my/os/windows/windows.pp'
}
else {
  import '../my/os/default/default.pp'
}

and I try CASE:

case $operatingsystem {
   redhat: { import '../my/os/linux/redhat.pp' }
   centos: { import '../my/os/linux/centos.pp' }
   windows: { import '../my/os/windows/windows.pp' } 
   default: { import '../my/os/default/default.pp' }
}

Why it didn't work? If I run puppet-agent, it read all pp-files and crash 
on windows-parameters on Linux or on linux-parameters on Windows. What I do 
incorrect?

-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.