if else statment is now working in puppet

246 views
Skip to first unread message

mohammed mathin

unread,
Nov 9, 2016, 5:14:18 PM11/9/16
to Puppet Users
Hi,

My questing will be silly but sorry for that

I facing problem on setting up the hostname based manifest

My requirement is if the hostname match statment1 file need to be print.

But in all the nodes statmen1 file is printing not sure where i have done mistake. hear the below my manifest file


class pkg::statment {
    if ["$hostname" == "172.20.14.173"] {
        file { '/tmp/statment1' :
            ensure => 'file',
            }
        }
    else {
        file { '/tmp/statment2' :
            ensure => 'file',
            }
         }
}


R.I.Pienaar

unread,
Nov 9, 2016, 5:44:40 PM11/9/16
to puppet-users


----- Original Message -----
> From: "mohammed mathin" <insham...@gmail.com>
> To: "puppet-users" <puppet...@googlegroups.com>
> Sent: Wednesday, 9 November, 2016 23:08:44
> Subject: [Puppet Users] if else statment is now working in puppet

> Hi,
>
> My questing will be silly but sorry for that
>
> I facing problem on setting up the hostname based manifest
>
> My requirement is if the hostname match statment1 file need to be print.
>
> But in all the nodes statmen1 file is printing not sure where i have done
> mistake. hear the below my manifest file
>
>
> class pkg::statment {
> if ["$hostname" == "172.20.14.173"] {

your hostname will not be an ip address, it will be like web1

add notify{"hostname is ${hostname}": } and see what it says

Peter Huene

unread,
Nov 9, 2016, 5:45:16 PM11/9/16
to puppet...@googlegroups.com
Hi Mohammed,

On Wed, Nov 9, 2016 at 2:08 PM, mohammed mathin <insham...@gmail.com> wrote:
Hi,

My questing will be silly but sorry for that

I facing problem on setting up the hostname based manifest

My requirement is if the hostname match statment1 file need to be print.

But in all the nodes statmen1 file is printing not sure where i have done mistake. hear the below my manifest file


class pkg::statment {
    if ["$hostname" == "172.20.14.173"] {

This is incorrect syntax for what you would like to accomplish.

`["$hostname" == "172.20.14.173"]` creates an array containing a single boolean (true if the strings compare or false if not).

The "if" expression is then given the array as the condition, which is always "truthy", causing '/tmp/statment1' to always be created.

If you remove the surrounding brackets, the "if" expression will then use the result of the equality operator as the condition, which is what you want.

Thus, change `if ["$hostname" == "172.20.14.173"] ...` to `if $hostname == "172.20.14.173" ...` (you can probably omit the quotes around $hostname as I suspect $hostname is already a string).

Cheers,

Peter
 
        file { '/tmp/statment1' :
            ensure => 'file',
            }
        }
    else {
        file { '/tmp/statment2' :
            ensure => 'file',
            }
         }
}


--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/7a6a23a8-1ac0-46d7-8b0e-13a04c82aa9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--
Peter Huene - Senior Software Engineer

peter...@puppet.com | @peterhuene
Reply all
Reply to author
Forward
0 new messages