[Puppet Users] how to check existences of a file in a ERB template?

2016-03-28 Thread Sans
Hi there,

I'm setting up a multi-tenancy WordPress environment, where multiple sites 
are structured as: /var/www/. Long story short: I want to put a 
line in the wp-config.php based on existences of a file in wp-content 
(under each site_location, provided by my users) directory, which I don't 
actively managed. So, I have this in the template that generates the 
wp-config.php file: 

<%- if File.exist?('/var/www/'+@title+'/wp-content/wp-extra-config.php') -%>
require_once(ABSPATH . 'wp-content/wp-extra-config.php');
<%- end -%>

where @title is the site_name that comes from a hiera hash. But it's not 
working and I think the reason being Puppet checking the existences of 
wp-extra-config.php file on the master during the compilation, hence 
setting it as false, for obvious reason. I cannot have it as a fact, 
because of the multi-tenancy and existences of that file varies from 
project to project. How do I go around this issue?

-San 


-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/15dd9afc-a55c-45d3-ab22-ed3ffc68fc3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Re: Concat and Exported Resources with dynamically generated targets

2016-03-28 Thread jcbollinger


On Friday, March 25, 2016 at 3:45:56 PM UTC-5, Tim Larkins wrote:
>
> Could anyone suggest the most 'puppet like' way of achieving the following 
> please?
>
> I'd like to make use of concat::fragments, within multiple modules, that 
> point to a dynamically defined 'target', e.g.
>
>   @@concat::fragment {"host_def_${::hostname}":
> target  => "/conf.d/*${::hostname}.conf*",
> content => template('foo/host.erb'),
> tag => 'host_def',
>   }
>
> Then in another module.. I'd like to collect those fragments to create 
> each of those target files - but the syntax is eluding me to the point that 
> I'm starting to try and over engineer a solution outside of puppet..
>


So for each node, there will be multiple such fragments, yes?  Their titles 
will have varying stems where in the example fragment you have "host_def_", 
or so I interpret you.  If there were only one fragment for each node then 
you would be better of exporting File resources instead.

 

>
>
> Elsewhere, where the name of the target file is statically defined, I've 
> just done something like this: 
>
> // Client module
>   @@concat::fragment {"host_def_${::hostname}":
> target  => "/conf.d/hosts.conf",
> content => template('foo/host.erb'),
> tag => 'host_def',
>   }
>
> // Master module
>  Concat::Fragment <<| tag == 'host_def' |>>
>
>  concat {'/conf.d/hosts.conf':
>  }
>
>
>
> However, in this scenario, I'm struggling to find a way to dynamically 
> generate that target reference within the master module..
>
>

I understand you to be saying that the problem is that you don't know *a 
priori* what the 'target's of the various Concat fragments will be.

 

> Do I need to explicitly generate a list of all 'targets' that generate 
> those fragments, so that I can go on to realise each explicitly?
>
> Or is there a way to abstract that away and automate the process by just 
> telling puppet to go through all of the matching tagged resources, group 
> them by target and realise the file automagically?
>
>

How about having each node export an appropriate Concat resource in 
addition to all the Concat::Fragment resources?  Then just collect the 
appropriate resources of both types on the node(s) where you want to manage 
the target files.


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/d6ad20e2-f4db-4f0d-b62f-5bfc5980f8e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.