Created
March 30, 2017 12:20
-
-
Save fvoges/7cf4bd687c77a9d15425fb6197a1a906 to your computer and use it in GitHub Desktop.
Puppet containment example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class myclass::config { | |
| # get the $config from the main class | |
| # and assignto local scope variable | |
| $config = $myclass::config | |
| file { $config: | |
| ensure => present, | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class myclass ( | |
| $package = $::myclas::params::package, | |
| $config = $::myclas::params::config, | |
| $service = $::myclas::params::service, | |
| ) inherits myclass::params { | |
| # contain here ensures that when you do something like | |
| # file { 'blah': | |
| # ensure => file, | |
| # require => Class['myclass'], | |
| # } | |
| # then all the resources from these subclasses will | |
| # be enforce BEFORE File['blah'] | |
| contain myclass::package | |
| contain myclass::config | |
| contain myclass::service | |
| # contain doesn't establish order between the subclasses, so we do that here | |
| Class['myclass::package'] -> Class['myclass::config'] ~> Class['myclass::service'] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class myclass::package { | |
| # get the $package from the main class | |
| # and assignto local scope variable | |
| $package = $myclass::package | |
| package { $package: | |
| ensure => present, | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class myclass::params ( | |
| case $::facts['os']['family'] { | |
| 'RedHat': { | |
| $package = 'value for RHEL' | |
| $config = 'value for RHEL' | |
| $service = 'value for RHEL' | |
| } | |
| 'Debian': { | |
| $package = 'value for Debian' | |
| $config = 'value for Debian' | |
| $service = 'value for Debian' | |
| } | |
| 'Windows': { | |
| $package = 'value for Windows' | |
| $config = 'value for Windows' | |
| $service = 'value for Windows' | |
| } | |
| default: { | |
| fail("Module ${module_name} is not supported on ${::facts['os']['name']}") | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class myclass::service { | |
| # get the $config from the main class | |
| # and assignto local scope variable | |
| $service = $myclass::service | |
| service { $service: | |
| ensure => running, | |
| enable => true, | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment