Tom De Vylder
2011-Aug-11 08:42 UTC
[Puppet Users] Distributing a PHP file as template fails
Hi all, I''m trying to distribute a PHP file as a template. The problem I''m running into is that each variable in the PHP file is recognized as a Puppet or ERB variable. Take this snippet for instance: # cat include/init.php <?php $dbhost = ''<%= app_dbhost %>''; $dbname = ''<%= app_dbname %>''; $dbuser = ''<%= app_dbuser %>''; $dbpass = ''<%= app_dbpass %>''; ?> When running this in Puppet I get the following error: info: Applying configuration version ''1311757652'' err: /Stage[main]/app::Config/File[/var/www/app/include/init.php]: Could not evaluate: Cannot find file: Invalid path ''$dbhost = ''localhost''; $dbname = ''app_db''; $dbuser = ''user1''; $dbpass = ''spoofed'';'' Could not retrieve file metadata for $dbhost = ''localhost''; $dbname = ''app_db''; $dbuser = ''user1''; $dbpass = ''spoofed'';: Cannot find file: Invalid path ''$dbhost = ''localhost''; $dbname = ''app_db''; $dbuser = ''user1''; $dbpass = ''spoofed'';'' at /etc/puppet/modules/app/manifests/init.pp:64 As you can see the actual ERB parts are filled in nicely but it fails on PHP''s variables. I''ve tried escaping the variables and equation marks. I''ve also renamed the php file not to end with *.erb. To no avail. Is there a way to avoid this behavior? Kind regards, TomDV -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Tom De Vylder
2011-Aug-11 08:52 UTC
[Puppet Users] Re: Distributing a PHP file as template fails
Forgot to mention some important details: # cat /etc/debian_version 6.0.2 # puppet --version # Take 1: Debian default 2.6.2 # puppet --version # take 2: Debian Backports 2.7.1 On 11 Aug 2011, at 10:42, Tom De Vylder wrote:> Hi all, > > I''m trying to distribute a PHP file as a template. > The problem I''m running into is that each variable in the PHP file is recognized as a Puppet or ERB variable. > > Take this snippet for instance: > > # cat include/init.php > <?php > $dbhost = ''<%= app_dbhost %>''; > $dbname = ''<%= app_dbname %>''; > $dbuser = ''<%= app_dbuser %>''; > $dbpass = ''<%= app_dbpass %>''; > ?> > > When running this in Puppet I get the following error: > > info: Applying configuration version ''1311757652'' > err: /Stage[main]/app::Config/File[/var/www/app/include/init.php]: Could not evaluate: Cannot find file: Invalid path ''$dbhost = ''localhost''; > $dbname = ''app_db''; > $dbuser = ''user1''; > $dbpass = ''spoofed'';'' Could not retrieve file metadata for $dbhost = ''localhost''; > $dbname = ''app_db''; > $dbuser = ''user1''; > $dbpass = ''spoofed'';: Cannot find file: Invalid path ''$dbhost = ''localhost''; > $dbname = ''app_db''; > $dbuser = ''user1''; > $dbpass = ''spoofed'';'' at /etc/puppet/modules/app/manifests/init.pp:64 > > As you can see the actual ERB parts are filled in nicely but it fails on PHP''s variables. > I''ve tried escaping the variables and equation marks. I''ve also renamed the php file not to end with *.erb. To no avail. > > Is there a way to avoid this behavior? > > Kind regards, > TomDV >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Daniel Pittman
2011-Aug-11 16:26 UTC
Re: [Puppet Users] Distributing a PHP file as template fails
On Thu, Aug 11, 2011 at 08:42, Tom De Vylder <tom@penumbra.be> wrote:> I''m trying to distribute a PHP file as a template. > The problem I''m running into is that each variable in the PHP file is recognized as a Puppet or ERB variable.That is pretty strange. So, I tested this to be sure, and I can manage create a file using that template just fine.> As you can see the actual ERB parts are filled in nicely but it fails on PHP''s variables. > I''ve tried escaping the variables and equation marks. I''ve also renamed the php file not to end with *.erb. To no avail. > > Is there a way to avoid this behavior?Well, it isn''t expected behaviour, so you *should* be just fine. Obviously, though, not so much. Can you post the actual declaration that creates the file, and the cached YAML catalog from the node that fails? Keep in mind that includes all the configuration data, so if you have passwords or whatever you might not want to do that. Thanks, daniel -- ⎋ Puppet Labs Developer – http://puppetlabs.com ♲ Made with 100 percent post-consumer electrons -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
vagn scott
2011-Aug-11 23:06 UTC
Re: [Puppet Users] Distributing a PHP file as template fails
On 08/11/2011 04:42 AM, Tom De Vylder wrote:> # cat include/init.php > <?php > $dbhost = ''<%= app_dbhost %>''; > $dbname = ''<%= app_dbname %>''; > $dbuser = ''<%= app_dbuser %>''; > $dbpass = ''<%= app_dbpass %>''; > ?> >Surely you mean (note the dash (-) ): <?php $dbhost = ''<%= app_dbhost -%>''; $dbname = ''<%= app_dbname -%>''; $dbuser = ''<%= app_dbuser -%>''; $dbpass = ''<%= app_dbpass -%>''; ?> -- vagn -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Tom De Vylder
2011-Aug-12 11:12 UTC
Re: [Puppet Users] Distributing a PHP file as template fails
On 12 Aug 2011, at 01:06, vagn scott wrote:> On 08/11/2011 04:42 AM, Tom De Vylder wrote: >> # cat include/init.php >> <?php >> $dbhost = ''<%= app_dbhost %>''; >> $dbname = ''<%= app_dbname %>''; >> $dbuser = ''<%= app_dbuser %>''; >> $dbpass = ''<%= app_dbpass %>''; >> ?> >> > > Surely you mean (note the dash (-) ): > > <?php > $dbhost = ''<%= app_dbhost -%>''; > $dbname = ''<%= app_dbname -%>''; > $dbuser = ''<%= app_dbuser -%>''; > $dbpass = ''<%= app_dbpass -%>''; > ?>I''ve always used the one without the dash. Anyways, I do get the same error using -%>. Tom -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Tom De Vylder
2011-Aug-12 11:43 UTC
Re: [Puppet Users] Distributing a PHP file as template fails
On 11 Aug 2011, at 18:26, Daniel Pittman wrote:> On Thu, Aug 11, 2011 at 08:42, Tom De Vylder <tom@penumbra.be> wrote: > >> I''m trying to distribute a PHP file as a template. >> The problem I''m running into is that each variable in the PHP file is recognized as a Puppet or ERB variable. > > That is pretty strange. So, I tested this to be sure, and I can > manage create a file using that template just fine. > >> As you can see the actual ERB parts are filled in nicely but it fails on PHP''s variables. >> I''ve tried escaping the variables and equation marks. I''ve also renamed the php file not to end with *.erb. To no avail. >> >> Is there a way to avoid this behavior? > > Well, it isn''t expected behaviour, so you *should* be just fine. > Obviously, though, not so much. > > Can you post the actual declaration that creates the file, and the > cached YAML catalog from the node that fails? Keep in mind that > includes all the configuration data, so if you have passwords or > whatever you might not want to do that.I''m pretty sure it does contain passwords and other sensitive information. Is there any other way? The file declaration isn''t anything out of the ordinary: file { "/var/www/app/include": ensure => directory; "/var/www/app/include/init.php": ensure => present, source => template ("app/init.php.erb"); } I''ve tried Vagn Scott''s suggestion to use "<%= var -%>" instead of "<%= var %>" and it still dies with the same error (below). The file really is there and if it wasn''t it should be created anyhow. Heck I''ve just tested with "/tmp": instead just to be sure. info: Applying configuration version ''1313148609'' err: /Stage[main]/Savane::Config/File[/var/ww/app/include/init.php]: Could not evaluate: Cannot find file: Invalid path ''<?php $sys_dbhost = ''localhost''; $sys_dbname = ''application''; $sys_dbuser = ''user1''; $sys_dbpass = ''spoofed''; ?>'' Could not retrieve file metadata for <?php $sys_dbhost = ''localhost''; $sys_dbname = ''application''; $sys_dbuser = ''user1''; $sys_dbpass = ''spoofed''; ?>: Cannot find file: Invalid path ''<?php $sys_dbhost = ''localhost''; $sys_dbname = ''application''; $sys_dbuser = ''user1''; $sys_dbpass = ''spoofed''; ?>'' at /etc/puppet/modules/savane/manifests/init.pp:91 TomDV -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Darren Chamberlain
2011-Aug-12 11:49 UTC
Re: [Puppet Users] Distributing a PHP file as template fails
On 8/12/2011 7:43 AM, Tom De Vylder wrote:> file { > "/var/www/app/include": > ensure => directory; > > "/var/www/app/include/init.php": > ensure => present, > source => template ("app/init.php.erb");content => template("app/init.php.erb");> }If you use source, it evaluates the template, then looks for a file with that name. I''ve been bitten by that many times as I change things from files to templates. -- Darren Chamberlain <darren@boston.com> -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Tom De Vylder
2011-Aug-12 12:01 UTC
Re: [Puppet Users] Distributing a PHP file as template fails
On 12 Aug 2011, at 13:49, Darren Chamberlain wrote:> On 8/12/2011 7:43 AM, Tom De Vylder wrote: >> file { >> "/var/www/app/include": >> ensure => directory; >> >> "/var/www/app/include/init.php": >> ensure => present, >> source => template ("app/init.php.erb"); > > content => template("app/init.php.erb"); > >> } > > If you use source, it evaluates the template, then looks for a file with that name. I''ve been bitten by that many times as I change things from files to templates.That seemed to fix it right away. Thanks! TomDV -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.