Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Declaring variable inside class

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

Declaring variable inside class

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

Declaring variable inside class

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