On 01/02/17 00:20, Joshua Schaeffer wrote:
> I'm new to Puppet and learning the program and language so this question
> might seem novice. I'm confused why I can assign an escape character to
> a variable but not inside any collection types (arrays or hashes). I was
> doing the simply motd puppet module and I created this:
>
> |
> $red ="^[[0;31m"
> $green ="^[[0;32m"
> $white ="^[[0;33m"
> $bold ="^[[1m"
> $unbold ="^[[22m"
> ...
> |
>
> Those "^[" characters are actual escape characters (a.k.a. echo -e
> \033[0;31m...). When I define my motd variable (which has the contents
> of /etc/motd) I can do this:
>
You are probably much better of encoding the UTF-8 characters using \u
as that will not screw up things if you cat the file etc.
> |
> $motd =@("END")
> Youare connecting
> to:*$**{bold}*${facts[hostname]}.${facts[networking]['domain']}*${unbold}
The *{bold} seems to miss a $ to interpolate the variale.
> ...
> ...
> END
> *
> |
>
> This works when I apply my manifest. Well, I thought having all those
> variables is stupid so I wanted to put them in a hash and just reference
> them by key:
>
> |
> color ={
That should be $color =
> 'red'=>"^[[0;31m",
> 'green'=>"^[[0;32m",
> 'white'=>"^[[0;33m",
> 'bold'=>"^[[1m",
> 'unbold'=>"^[[22m",
> }
> ...
> $motd =@("END")
> Youare connecting
> to:*$**{color['bold']}*${facts[hostname]}.${facts[networking]['domain']}${color['unbold']}*
The *{color...} seems to miss a $ to interpolate the variable.
> ...
> ...
> END*
> |
>
> However this produces an error
>
> |
> $puppet apply --environment sandbox ./manifests/
> Error:Illegalattempt to assign to 'a Name'.Notan assignable reference at
> /etc/puppetlabs/code/environments/sandbox/modules/motd/manifests/init.pp:53:2on
> node
fenix.harmonywave.com
The 53:2 should point at where the assignment to color (without $) is
done. The "color" is a NAME when not preceded by a $.
- henrik
--
Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/