Dynamic template path


#1

I need to create a template for network scripts, eg:

template “/etc/sysconfig/network-scripts/ifcfg-xxx” do
.
end

Where “xxx” is specified in either default or override attributes. I have
tried:

template “/etc/sysconfig/network-scripts/ifcfg-xxxi#{node[‘xxx’]}” do
template “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’] do

path = “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’]
template path do

but all give knife upload errors of the form:
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:46:
syntax error, unexpected tIDENTIFIER, expecting ‘]’

Suggestions please.


#2

can we see a little more of your recipe? I do something similar in my
recipes without issue.

-Jesse

On Tue, May 22, 2012 at 2:09 PM, crlb@uvic.ca wrote:

I need to create a template for network scripts, eg:

template “/etc/sysconfig/network-scripts/ifcfg-xxx” do
.
end

Where “xxx” is specified in either default or override attributes. I have
tried:

template “/etc/sysconfig/network-scripts/ifcfg-xxxi#{node[‘xxx’]}” do
template “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’] do

path = “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’]
template path do

but all give knife upload errors of the form:
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:46:
syntax error, unexpected tIDENTIFIER, expecting ‘]’

Suggestions please.


#3

FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:46:
syntax error, unexpected tIDENTIFIER, expecting ‘]’

From the message it looks like you have an unmatched [. Perhaps an
array that isn’t closed. Perhaps a node attribute missing a ’ or ].
Perhaps a string with single or double quotes unclosed. Somewhere on,
or before, line 46 in KVM_VMM_control_node.rb. If you need anything
more than that, please pastebin the code.

Eric G. Wolfe
Senior Linux Administrator,
IT Infrastructure Systems

Marshall University Computing Services
Drinko Library 428-K
One John Marshall Dr.
Huntington, WV 25755
Phone: 304.942.3970
Email: eric.wolfe@marshall.edu

You will be recognized and honored as a community leader.

On 05/22/2012 02:09 PM, crlb@uvic.ca wrote:

I need to create a template for network scripts, eg:

template “/etc/sysconfig/network-scripts/ifcfg-xxx” do
.
end

Where “xxx” is specified in either default or override attributes. I have
tried:

template “/etc/sysconfig/network-scripts/ifcfg-xxxi#{node[‘xxx’]}” do
template “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’] do

path = “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’]
template path do

but all give knife upload errors of the form:
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:46:
syntax error, unexpected tIDENTIFIER, expecting ‘]’

Suggestions please.


#4

I hope this isn’t something stupid like a typo. I was beginning to
believe that a template could not specify a variable path. Here’s the info:

The attribute:

default[‘nimbus’][‘control’][‘network_bridge’] = ‘br0’

The recipe:

template “/etc/sysconfig/network-scripts/ifcfg-” +
node[‘nimbus’[‘control’][‘network_bridge’] do
source "bridg.erb"
owner "root"
group "root"
mode "0644"
end

The template:

DEVICE=<%= node[‘nimbus’][‘control’][‘network_bridge’] %>
TYPE=Bridge
BOOTPROTO=static
IPADDR=<%= node[‘ipaddress’] %>
NETMASK=255.255.255.0
ONBOOT=yes
DELAY=0
NM_CONTROLLED=no

The error:

[crlb@heplw34 nimbus]$ knife cookbook upload nimbus
Uploading nimbus [0.0.1]
FATAL: Cookbook file recipes/KVM_VMM_control_node.rb has a ruby syntax
error:
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:45:
syntax error, unexpected kDO, expecting ']'
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:50:
syntax error, unexpected kEND, expecting end [crlb@heplw34 nimbus]

Thanks for your help, Colin.

On 05/22/2012 11:26 AM, Jesse Campbell wrote:

can we see a little more of your recipe? I do something similar in my
recipes without issue.

-Jesse

On Tue, May 22, 2012 at 2:09 PM,crlb@uvic.ca wrote:

I need to create a template for network scripts, eg:

template “/etc/sysconfig/network-scripts/ifcfg-xxx” do
.
end

Where “xxx” is specified in either default or override attributes. I have
tried:

template “/etc/sysconfig/network-scripts/ifcfg-xxxi#{node[‘xxx’]}” do
template “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’] do

path = “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’]
template path do

but all give knife upload errors of the form:
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:46:
syntax error, unexpected tIDENTIFIER, expecting ‘]’

Suggestions please.


#5

s/node[‘nimbus’[‘control’][‘network_bridge’]/node[‘nimbus’][‘control’][‘network_bridge’]/

Eric G. Wolfe
Senior Linux Administrator,
IT Infrastructure Systems

Marshall University Computing Services
Drinko Library 428-K
One John Marshall Dr.
Huntington, WV 25755
Phone: 304.942.3970
Email: eric.wolfe@marshall.edu

You will be recognized and honored as a community leader.

On 05/22/2012 02:42 PM, Colin Leavett-Brown wrote:

I hope this isn’t something stupid like a typo. I was beginning to
believe that a template could not specify a variable path. Here’s the
info:

The attribute:

default[‘nimbus’][‘control’][‘network_bridge’] = ‘br0’

The recipe:

template “/etc/sysconfig/network-scripts/ifcfg-” +
node[‘nimbus’[‘control’][‘network_bridge’] do
source "bridg.erb"
owner "root"
group "root"
mode "0644"
end

The template:

DEVICE=<%= node[‘nimbus’][‘control’][‘network_bridge’] %>
TYPE=Bridge
BOOTPROTO=static
IPADDR=<%= node[‘ipaddress’] %>
NETMASK=255.255.255.0
ONBOOT=yes
DELAY=0
NM_CONTROLLED=no

The error:

[crlb@heplw34 nimbus]$ knife cookbook upload nimbus
Uploading nimbus [0.0.1]
FATAL: Cookbook file recipes/KVM_VMM_control_node.rb has a ruby syntax
error:
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:45:
syntax error, unexpected kDO, expecting ']'
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:50:
syntax error, unexpected kEND, expecting end [crlb@heplw34 nimbus]

Thanks for your help, Colin.

On 05/22/2012 11:26 AM, Jesse Campbell wrote:

can we see a little more of your recipe? I do something similar in my
recipes without issue.

-Jesse

On Tue, May 22, 2012 at 2:09 PM,crlb@uvic.ca wrote:

I need to create a template for network scripts, eg:

template “/etc/sysconfig/network-scripts/ifcfg-xxx” do
.
end

Where “xxx” is specified in either default or override attributes. I
have
tried:

template “/etc/sysconfig/network-scripts/ifcfg-xxxi#{node[‘xxx’]}” do
template “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’] do

path = “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’]
template path do

but all give knife upload errors of the form:
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:46:

syntax error, unexpected tIDENTIFIER, expecting ‘]’

Suggestions please.


#6

Sorry, I’ve just seen the typo in the template definition. Colin.

On 05/22/2012 11:42 AM, Colin Leavett-Brown wrote:

I hope this isn’t something stupid like a typo. I was beginning to
believe that a template could not specify a variable path. Here’s the info:

The attribute:

default[‘nimbus’][‘control’][‘network_bridge’] = ‘br0’

The recipe:

template “/etc/sysconfig/network-scripts/ifcfg-” +
node[‘nimbus’[‘control’][‘network_bridge’] do
source "bridg.erb"
owner "root"
group "root"
mode "0644"
end

The template:

DEVICE=<%= node[‘nimbus’][‘control’][‘network_bridge’] %>
TYPE=Bridge
BOOTPROTO=static
IPADDR=<%= node[‘ipaddress’] %>
NETMASK=255.255.255.0
ONBOOT=yes
DELAY=0
NM_CONTROLLED=no

The error:

[crlb@heplw34 nimbus]$ knife cookbook upload nimbus
Uploading nimbus [0.0.1]
FATAL: Cookbook file recipes/KVM_VMM_control_node.rb has a ruby syntax
error:
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:45:
syntax error, unexpected kDO, expecting ']'
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:50:
syntax error, unexpected kEND, expecting end [crlb@heplw34 nimbus]

Thanks for your help, Colin.

On 05/22/2012 11:26 AM, Jesse Campbell wrote:

can we see a little more of your recipe? I do something similar in my
recipes without issue.

-Jesse

On Tue, May 22, 2012 at 2:09 PM,crlb@uvic.ca wrote:

I need to create a template for network scripts, eg:

template “/etc/sysconfig/network-scripts/ifcfg-xxx” do
.
end

Where “xxx” is specified in either default or override attributes. I have
tried:

template “/etc/sysconfig/network-scripts/ifcfg-xxxi#{node[‘xxx’]}” do
template “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’] do

path = “/etc/sysconfig/network-scripts/ifcfg-” + node[‘xxx’]
template path do

but all give knife upload errors of the form:
FATAL:
/hepuser/crlb/Git/chef-repo/cookbooks/nimbus/recipes/KVM_VMM_control_node.rb:46:
syntax error, unexpected tIDENTIFIER, expecting ‘]’

Suggestions please.