On Thursday, March 30, 2017 at 12:58:46 PM UTC-5, Peter K wrote:
> I've tried exec and sed, but I couldn't figure out the necessary escaping
> to get the filename variable to parse (here I test with 'abc'):
> define removeMinimumUID(){
> exec { '${filename}':
> command => "/usr/bin/sed -i \'s|abc|cab|g\' ${filename}",
> onlyif => '/usr/bin/test -e ${filename}',
> refresh => '/usr/bin/true',
> provider => 'posix',
> logoutput => on_failure,
> }
> }
>
> RemoveMinimumUID { "/mnt/NY_Interactive/dev/peter/puppet/abc.txt": }
>
> Error:
> Executing: '/usr/bin/sed -i 's|abc|cab|g' '^[[0m
> ^[[mNotice:
> /Stage[main]/Main/Removeminimumuid[/mnt/NY_Interactive/dev/peter/puppet/abc.txt]/Exec[${filename}]/returns:
>
> /usr/bin/sed: no input files^[[0m
>
>
This is only incidentally an escaping problem. The main issue is that the
defined type you present uses a variable $filename from the local scope,
but you do not define any such variable in the local scope. Therefore,
when evaluated as a variable reference, $filename expands to nothing. You
can in fact see that in the command string that the exec reports itself to
be using. It looks like you meant to use $title instead, or perhaps to
define $filename = $title.
Having fixed that, your Exec resource ought to work despite the quoting /
escaping problem associated with its title. For the record, however, you
can solve that minor issue by changing the single quotes to double quotes (
"${filename}") or by omitting them altogether. Personally, though, since
you're not using the command itself as the title, I would provide a more
descriptive title, something like
exec { "remove minimum UID in ${filename}":
# ...
}
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/805a11ee-835a-4c1d-bcc3-6e174ca11caf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.