Case Statement for setting IP addresses

41 views
Skip to first unread message

James Taylor

unread,
Dec 11, 2014, 2:23:51 PM12/11/14
to puppet...@googlegroups.com
Hello all,

I am working with an issue that has me tied up in knots. I have a group of machines that will have structured names (i.e. prj-sfo-ibm-102.foo.com). I want to use the host name to assign IP addresses to the machine, since each host name has a locator (sfo), vendor (ibm), and node number ("1" signifies a virtual machine and the "02" is the node number). Here is what I have come up with:

__________________________

node /^prj-(sfo|nyc)-(ibm|apple|maxtor|quantum|intel)-1(0|1)(0|1|2|3|4|5|6|7|8|9)\.foo\.com$/ {

    $h = split($hostname,"-")

    $site = $h[1]

    $vendor = $h[2]

    case $vendor {


        ibm :        {

            $net    =    "10.227.140."
            $mask    =    "255.255.255.248"
            $ip    =    "171"
            $addr    =    $net$ip

        }

        default:    {

            notice { "Vendor item in hostname is out of scope."},
            err { "Vendor item in hostname is out of scope."},

        }

    }


    file {"/root/temp.txt":

        content    =>    "
$hostname $site $vendor $net $mask $ip $addr
",

        owner    =>    root,
        group    =>    group,
               

            }

}

__________________________

I am using the hostname prj-sfo-ibm-102.foo.com but the structure keeps breaking with a "Syntax error at '}'; expected '}' at /etc/puppet/manifests/nodes.pp:19 on node prj-sfo-ibm-102.foo.com"

I have looked in a couple of books and a number of websites, the structure looks correct... A little help?


--
James

Peter Bukowinski

unread,
Dec 11, 2014, 2:38:28 PM12/11/14
to puppet...@googlegroups.com
> On Dec 11, 2014, at 2:23 PM, James Taylor <jameskir...@gmail.com> wrote:
>
> default: {
>
> notice { "Vendor item in hostname is out of scope."},
> err { "Vendor item in hostname is out of scope."},

Using parentheses for the notice and err functions instead of braces should get you past the syntax error.

notice("Vendor item in hostname is out of scope."),
err("Vendor item in hostname is out of scope."),


--
Peter

James Taylor

unread,
Dec 16, 2014, 7:13:52 PM12/16/14
to puppet...@googlegroups.com


Ok,

I found the problem.

On the line with:

            $addr    =    $net$ip

Should look like this:

            $addr    =    "$net$ip"


Plus a quick "thank you" to Peter Bukowinski for the correction, I have clean running test code.

--
James
Reply all
Reply to author
Forward
0 new messages