Remove lines from template if condition

Hello.

In a template hazelcast.xml.erb file I have the following code:

<% if @cluster -%>
<% node['hazelcast']['clusteredips'].each do |ip| %>
<member><%= "#{ip}"%></member>
<% end %>
<% else -%>
<member><%= node['hazelcast']['ip-local']%></member>
<% node['hazelcast']['clusteredips'].each do |ip| %>
<member><%= "#{ip}"%></member>
<% end %>
<% end %>

@cluster comes from a boolean attribute and basically says that if that variable is true, then add a 192.168.x.x line for each value of the clusteredips array variable.

But if I need to apply the recipe to a machine which is not clustered anymore, i need the recipe to remove the old IPs and to leave only on IP, the one of the machine.

Is that possible?
Or I have to remove the conf file and recreate it?

Is there a better solution?

Thank you,
Gabriel

In this scenario, if your node is no longer clustered, the template resource will render file contents that differ from the contents when the node was clustered. So unless your template resource is using the :create_if_missing action, this difference should cause your template to reconverge and be replaced with new content.