Modify class variable in puppet

22 views
Skip to first unread message

CedrX

unread,
Feb 12, 2014, 8:16:33 AM2/12/14
to puppet...@googlegroups.com
Hi
I would like to modify a class variable.
This variable contains a list of packages to install
The goal is to make this list of packages different for each type of os (case $operatingsystem)

Here uis my code

class pack_utils {
        $packages = [
          "curl",
          "htop",
          "lshw",
          "lsof"
        ]
       
     case $operatingsystem {
           debian, ubuntu : {
                        #  Here i would like to add packages name in array packages defined above
                        notice("value of packages: $packages")

           }
        }
 

        package { $packages:
                  ensure => present,
        }

 }

How i can do to modify the value of $packages ?
Thanks in advance

CedrX

CedrX

unread,
Feb 12, 2014, 8:52:38 AM2/12/14
to puppet...@googlegroups.com
I have the answer.
I read here : https://groups.google.com/forum/#!topic/puppet-users/I9Y-p3UY8JE that variables are immutable

Johan De Wit

unread,
Feb 12, 2014, 9:08:00 AM2/12/14
to puppet...@googlegroups.com
have a look at hiera ta achieve what you want.

If you have an hierarchy like

"%{::osfamily}"

You can create some yaml files in

etc/puppet/hieradata/RedHat.yaml

---
  pack_util::packages:
    - curl
    - htop
   

and in

/etc/puppet hieradata/Debian.yaml


---
  pack_util::packages:
    - curl_deb
    - htop_deb
  

And so on.

Assuming you are using puppet 3

This is one possible way, and check the docs for the correct syntax and usage, but is shouls get you going

Hope this helps

Jo
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/61285dae-5535-4794-8cd4-293081d13196%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


-- 
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer         (805008667232363)
Puppet Certified Professional 2013 (PCP0000006)
_________________________________________________________
 
Open-Future                 Phone     +32 (0)2/255 70 70
Zavelstraat 72              Fax       +32 (0)2/255 70 71
3071 KORTENBERG             Mobile    +32 (0)474/42 40 73
BELGIUM                     http://www.open-future.be
_________________________________________________________
 

Upcoming Events:

Zabbix Certified Training | http://www.open-future.be/zabbix-certified-training-10-till-12th-march

Zabbix for Large Environments Training | http://www.open-future.be/zabbix-large-environments-training-13-till-14th-march

Puppet Introduction Course | http://www.open-future.be/puppet-introduction-course-14th-april

Puppet Advanced Training | http://www.open-future.be/puppet-advanced-training-15-till-17th-april

Subscribe to our newsletter: http://eepurl.com/BUG8H


Rafael Cristaldo

unread,
Feb 12, 2014, 9:10:24 AM2/12/14
to puppet...@googlegroups.com


I think this is the best way!

# Class packages

 class pack_utils {

        case $operatingsystem {
          'debian','ubuntu' : {$packages = 'apache2'}

          'redhat','centos' : {$packages = 'httpd'}
        }

        package { $packages:
                  ensure => installed,
        }

 }

Reply all
Reply to author
Forward
0 new messages