Ask Your Question
0

Declaring variable inside class

asked 2015-08-18 09:21:13 -0500

iron_michael86 gravatar image

updated 2015-08-18 09:24:13 -0500

I am trying to declare variable inside class .But I get undef when I run it on the client side . How do we go about this in puppet in init.pp since the module uses the variables as an argument.

$url=""
$user=""
$pass=""
if $dtap == 'D' {
    $url="https://test1.example.com/XMLRPC"
    $user="user1"
    $pass="password1"
}
elsif $dtap == 'T' {
    $url="https://test1.example.com/XMLRPC"
    $user="user1"
    $pass="password1"
}
else {
    $url="https://test2.example.com/XMLRPC"
    $user="user2"
    $pass="password2"
}

class rhnsatellite(
  $server_url  = $url,
  $username = $user,
  $password = $pass
) {

  # Read by the provider on the machine, to log into RHN and
  # change subscriptions.
  file {'/etc/puppetlabs/puppet/rhn.conf':
    owner   => root,
    group   => root,
    mode    => 0600,
    content => template('rhnsatellite/rhn.conf.erb')
  }
}

Client side error

Debug: Executing 'diff -u /etc/puppetlabs/puppet/rhn.conf /tmp/puppet-file20150818-7743-lgr0up'
Notice: /Stage[main]/Rhnsatellite/File[/etc/puppetlabs/puppet/rhn.conf]/content:
--- /etc/puppetlabs/puppet/rhn.conf     2015-08-18 15:11:44.195100850 +0200
+++ /tmp/puppet-file20150818-7743-lgr0up        2015-08-18 15:26:02.303213717 +0200
@@ -1,3 +1,3 @@
-server_url = undef
-username = undef
-password = undef
+server_url =
+username =
+password =

Debug: Finishing transaction 23552520
Info: FileBucket adding {md5}b39c8b5759e6ec924182d0df9d005ee2
Info: /Stage[main]/Rhnsatellite/File[/etc/puppetlabs/puppet/rhn.conf]: Filebucketed     /etc/puppetlabs/puppet/rhn.conf to puppet with sum b39c8b5759e6ec924182d0df9d005ee2
Notice: /Stage[main]/Rhnsatellite/File[/etc/puppetlabs/puppet/rhn.conf]/content: content changed '{md5}b39c8b5759e6ec924182d0df9d005ee2' to '{md5}dfc303c73e26db1b112e171115784a11'
Debug: /Stage[main]/Rhnsatellite/File[/etc/puppetlabs/puppet/rhn.conf]:

Is there a way to solve this error , I am trying to implement with the following condition , I am using this module https://github.com/andytinycat/puppet-rhnsatellite.

And want to call this rhnsatellite in the site.pp

    node 'testnode' {
    include vmware
    include rhnsatellite
    satelliterepo { 'base-stash-el6':
    ensure => 'present',
    }

    include sudo
    include sssd
    include hardening
    include base-httpd
    include hpom
    class { sshd: }
}

Since we have mutiple node we need to make sure we have this condition placed in init.pp

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-08-21 10:37:08 -0500

johnnyb04 gravatar image

I tend to not use class parameters, but would this work?

class rhnsatellite {
  case $dtap {
    "D": { $server_url="https://test1.example.com/XMLRPC"
           $username="user1"
           $password="password1"}
    "T": { $server_url="https://test1.example.com/XMLRPC"
           $username="user1"
           $password="password1"
    default: { $server_url="https://test2.example.com/XMLRPC"
               $username="user2"
               $password="password2"
  } 

  file {'/etc/puppetlabs/puppet/rhn.conf':
    owner   => root,
    group   => root,
    mode    => 0600,
    content => template('rhnsatellite/rhn.conf.erb')
  }
}
edit flag offensive delete link more

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-08-18 09:21:13 -0500

Seen: 231 times

Last updated: Aug 21 '15