How to use variables in a puppet class

298 views
Skip to first unread message

Vikas Kumar

unread,
Jul 24, 2014, 3:07:51 AM7/24/14
to puppet...@googlegroups.com
Hello All,

I have a kickstart server which I use to deploy many minor versions of CentOS/RHEL 5 and 6 for both 32 and 64 Bit OS.

I have lots of yum repository files. For. e.g. - RHEL_5.5_64.repo, RHEL_5.6_64.repo, RHEL_6.2_32, RHEL_6.5_64, etc. I am looking to use Puppet to automatically deploy the required kickstart repos. I tried to follow this link in vain.

The problem is that I am unable to use facter variables $lsbdistrelease with something like below.


Here, the variable does not converts to is value.

Please help me to get this sorted. Am I missing anything ?

Regards,
Vikas

Sean Crosby

unread,
Jul 24, 2014, 8:14:59 AM7/24/14
to puppet...@googlegroups.com
Hi Vikas,

Do you have the package 'redhat-lsb' installed? The $lsbdistrelease fact is only populated when this package is installed

Sean


--
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/59aa2148-3133-48fc-9731-412d8687c4f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Juan Moreno

unread,
Jul 24, 2014, 12:18:42 PM7/24/14
to puppet...@googlegroups.com
Hi,

You can try to execute facter in the nodes, with this you can see the facter availables.

It's posibble that lsbdistrelease is not available, but operatingsystemrelease works properly.

This is because lsbdistrelease uses a package and operatingsystemrelease read from a file /etc/redhat-release in RedHat distros

for instance, in my machine, I obtain the two values:

$ facter | egrep 'lsbdistrelease|operatingsystemrelease'
lsbdistrelease
=> 14.04
operatingsystemrelease
=> 14.04

cheers,
Juan Moreno

Vikas Kumar

unread,
Jul 24, 2014, 7:20:11 PM7/24/14
to puppet...@googlegroups.com
Hi Sean/Juan,

Yes, the redhat-lsb package is installed on my RedHat 6.4 machine which is my Puppet Client server. Puppet server is Ubuntu 14.04.

root@box27:~# rpm -qa | grep redhat-lsb
redhat
-lsb-graphics-4.0-7.el6.x86_64
redhat
-lsb-compat-4.0-7.el6.x86_64
redhat
-lsb-core-4.0-7.el6.x86_64
redhat
-lsb-4.0-7.el6.x86_64
redhat
-lsb-printing-4.0-7.el6.x86_64
root@box27
:~#


Also, facter is also displaying desired values.

root@box27:~# facter | egrep 'lsbdistrelease|operatingsystemrelease'
lsbdistrelease
=> 6.4

operatingsystemrelease
=> 6.4
root@box27
:~#

And, I am using puppet v3.6.2-1 (installed through RPMs).

Not sure what I am missing. I have also tried to use file resource with various combinations to make the variables work as below in vain.

        file {'/etc/yum.repos.d/RHEL-6.4.repo':
        ensure => present,
        mode   => '0644',
        owner  => 'root',
        group  => 'root',
        source => 'puppet:///modules/repo/rhel-${lsbdistrelease}_64.repo',
        or
        source => 'puppet:///modules/repo/rhel-$lsbdistrelease_64.repo',
                or
                
source => 'puppet:///modules/repo/rhel-'$lsbdistrelease'_64.repo',
        or
                source => 'puppet:///modules/repo/rhel-"$lsbdistrelease"_64.repo',
        }

Any other ideas. 

Regards,
Vikas

CD

unread,
Jul 24, 2014, 7:37:17 PM7/24/14
to puppet...@googlegroups.com
Hi Vikas,

This is not the solution to your question but possibly alternative option.

It seems you want to generate a yum repo url for specific OS version so that it picks-up correct version arch etc.

How about if you use following and set up repos to match. 
baseurl=http://<repo server>/centos/$releasever/os/$basearch/

Regards,
CD

Vikas Kumar

unread,
Jul 24, 2014, 7:44:39 PM7/24/14
to puppet...@googlegroups.com
Hi CD,

Just tried these too, but somehow puppet is not honoring any variables in the resources. 

and

Somehow, notify is working fine.

notify {'FYI': message => "Setting up Repo for a $operatingsystem $lsbdistrelease system", }


Regards,
Vikas

José Luis Ledesma

unread,
Jul 25, 2014, 3:03:34 AM7/25/14
to puppet...@googlegroups.com

If you interpolate variable you have to use " instead of '.
So it should be


source => "puppet:///modules/repo/rhel-${::lsbdistrelease}_64.repo",

Regards,

--
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.

Vikas Kumar

unread,
Jul 25, 2014, 3:22:40 AM7/25/14
to puppet...@googlegroups.com

Hi Jose,

I tried this, didn't worked for me :(

      '6': {

        file
{'/etc/yum.repos.d/RHEL-6.4.repo':
       
ensure => present,
        mode  
=> '0644',
        owner  
=> 'root',
       
group  => 'root',

        source
=> 'puppet:///modules/repo/rhel-${::lsbdistrelease}_64.repo',
       
}

Got this message in the log file.

Fri Jul 25 12:51:12 +0530 2014 /Stage[main]/Repo::Rhel/File[/etc/yum.repos.d/RHEL-6.4.repo] (err): Could not evaluate: Could not retrieve information from environment production source(s) puppet:///modules/repo/rhel-${::lsbdistrelease}_64.repo

This is the file on the server.

# ls -l /etc/puppet/modules/repo/files/rhel-6.4_64.repo
-rw-r--r-- 1 root root 205 Jul 24 12:09 /etc/puppet/modules/repo/files/rhel-6.4_64.repo
#

Have I made a mistake anywhere ? 

Thanks in advance.


Regards,
Vikas

Johan De Wit

unread,
Jul 25, 2014, 3:56:37 AM7/25/14
to puppet...@googlegroups.com
use double quotes in your source attribute :


source => "puppet:///modules/repo/rhel-${::lsbdistrelease}_64.repo",



--
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.

For more options, visit https://groups.google.com/d/optout.


-- 
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer              (805008667232363)
Puppet Certified Professional 2013/2014 (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:

Linux Training | https://www.open-future.be/linux-training-8-till-12th-september

Puppet Introduction Course | https://www.open-future.be/puppet-introduction-course-15th-september

Puppet Fundamentals Training | https://www.open-future.be/puppet-fundamentals-training-16-till-18th-september

Zabbix Certified Specialist | https://www.open-future.be/zabbix-certified-specialisttraining-22-till-24th-september

Zabbix Certified Professional | https://www.open-future.be/zabbix-certified-professional-training-25-till-26th-september

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


Vikas Kumar

unread,
Jul 25, 2014, 5:28:03 AM7/25/14
to puppet...@googlegroups.com
Super Johan !!

Thanks a ton. You made my day.

Now, these statements are working fine.

and
source => "puppet:///modules/repo/rhel-${::lsbdistrelease}_64.repo",

Regards,
Vikas
Reply all
Reply to author
Forward
0 new messages