# concat fragments based on certain conditions

The normal usage of the concat module would be to create a bunch of fragments and put them together in a file. This is very easy and clear. For a new project I have a concat-file that consists of 4 fragments. 2 fragments (the first and the last) are created on the node where the final file should be placed (node1). The other 2 fragments are created via Exported resources (on node2) in a defined resource and are later collected on node1.

In practice not all fragments should be collected by node1. If a parameter nonssl has value false only one of the exported resource should be collected. I tried adding tags to the exported resources and use those in the collection, but that didn't seem to work

if nonssl == true{
Module::Exportedresources <<| tag == 'nonssl' |>>
}

Module::Exportedresources <<| tag == 'ssl' |>>


I also tried to include this condition in the defined resource as well. So the resource would only create an exported resource when the condition was met. But that also didn't get me what I needed.

What am I missing? Is there a better way of doing this?

EDIT: I have made a simplified version of the setup as an example of what I would like to achieve. Maybe it can help finding a solution

Node configs:

node 'node1'{
configfile {'server_config':
nonssl => true,
}
}

node 'node2'{
@@configfile:::exportedresources {"elements_${fqdn}": port => '9999', host => 'node1', } }  config file definition: define configfile( nonssl = false,) { concat { "final_file_${fqdn}":
path => '/tmp/final_file',
owner => 'root',
group => 'root',
}

concat::fragment {"00_part1_${fqdn}": target => "final_file_${fqdn}",
content => template('module/part1.erb'),
}

if nonssl == true{
Configfile::Exportedresources <<| host == $::fqdn and tag == 'nonssl' |>> } concat::fragment { "20_part3_${fqdn}":
target => "final_file_${fqdn}", content => template('module/part3.erb'), } Configfile::Exportedresources <<| host ==$::fqdn and tag == 'ssl' |>>

concat::fragment { "40_part5_${fqdn}": target => 'final_file_${fqdn}',
content => template('module/part5.erb'),
}
}


definition for the exported resources

define configfile::Exportedresources(
port = undef,
enabled = true,
host = undef,) {

concat::fragment { "10_part2_${fqdn}_non_ssl": target => "final_file_${host}",
content => template('module/part2.erb'),
tag => 'nonssl',
}

concat::fragment { "10_part2_${fqdn}_ssl": target => "final_file_${host}",
content => template('module/part2.erb'),
tag => 'ssl',
}
}


at this point everything is working as it should, except the conditional part.

edit retag close merge delete