Grrr. I have the exec{} below in my puppet module. How do I escape the \ characters? I''ve tried every possible combination I can think of. I''ve used one, I''ve used two, and I''ve used THREE \. exec { ''oracle-extract-part'': command => "/usr/bin/printf \"n\np\n2\n2091\n+16384M\nw\n\" | /sbin/fdisk /dev/xvdj", unless => "/bin/cat /proc/partitions | /bin/grep ${orcl_ephm_device}2"; } With three \, it ends up looking like this in the log: Nov 21 01:27:45 dev-c3-app-15 puppet-agent[3091]: (/Stage[main]/Oracle::Server11g/Exec[oracle-swap-part]/returns) change from notrun to 0 failed: /usr/bin/printf \"n\#012p\#0121\#0121\#012+32768M\#012t\#01282\#012w\#012\" | /sbin/fdisk /dev/xvdj returned 1 instead of one of [0] at /etc/puppet/devmp/modules/oracle/manifests/server11g.pp:136 Now... that''s obviously not right. How do I escape \ symbols? Doug. -- 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.
I''d deploy a wee script that does what you are trying to handle in the command string, and just call that instead. On 21 Nov 2011, at 06:30, Douglas Garstang wrote:> Grrr. I have the exec{} below in my puppet module. How do I escape the > \ characters? I''ve tried every possible combination I can think of. > I''ve used one, I''ve used two, and I''ve used THREE \. > > exec { > ''oracle-extract-part'': > command => "/usr/bin/printf > \"n\np\n2\n2091\n+16384M\nw\n\" | /sbin/fdisk /dev/xvdj", > unless => "/bin/cat /proc/partitions | /bin/grep > ${orcl_ephm_device}2"; > } > > With three \, it ends up looking like this in the log: > > Nov 21 01:27:45 dev-c3-app-15 puppet-agent[3091]: > (/Stage[main]/Oracle::Server11g/Exec[oracle-swap-part]/returns) change > from notrun to 0 failed: /usr/bin/printf > \"n\#012p\#0121\#0121\#012+32768M\#012t\#01282\#012w\#012\" | > /sbin/fdisk /dev/xvdj returned 1 instead of one of [0] at > /etc/puppet/devmp/modules/oracle/manifests/server11g.pp:136 > > Now... that''s obviously not right. How do I escape \ symbols? > > Doug. > > -- > 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. >-- 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.
> exec { > ''oracle-extract-part'': > command => "/usr/bin/printf > \"n\np\n2\n2091\n+16384M\nw\n\" | /sbin/fdisk /dev/xvdj", > unless => "/bin/cat /proc/partitions | /bin/grep > ${orcl_ephm_device}2"; > }if you don''t need to interpolate a variable, you can simply use single quotes, so you don''t need to escape anything. grrr ~pete -- 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.
On 11/21/2011 01:30 AM, Douglas Garstang wrote:> Grrr. I have the exec{} below in my puppet module. How do I escape the > \ characters? I''ve tried every possible combination I can think of. > I''ve used one, I''ve used two, and I''ve used THREE \. > > exec { > ''oracle-extract-part'': > command => "/usr/bin/printf > \"n\np\n2\n2091\n+16384M\nw\n\" | /sbin/fdisk /dev/xvdj", > unless => "/bin/cat /proc/partitions | /bin/grep > ${orcl_ephm_device}2"; > }Sounds like you need to use FOUR. Say you wanted to use printf to print a newline. You would run this: (1) printf \n But, the backslash has special meaning in bash (or most shells). If you type that in bash, you have to escape it, one of these ways: (2) printf \\n (3) printf ''\n'' Puppet runs commands through a shell. So, you will have to apply escaping appropriate for whatever shell is in use. But, the command is also in a string. Backslashes have special meaning in puppet strings. So, we know the command we want to give to bash is: (4) printf \\n To put that in a puppet string we need to escape the \: (5) "printf \\\\n" If you don''t like all the backslashes, you could give single quotes to bash: (6) "printf ''\\n''" This is example 3, quoted with puppet''s rules. You could also use single quotes in Puppet, but Puppet''s single-quote strings still find special meaning in \, so it doesn''t really get you anything, and if you are using single quotes for bash it''s actually worse. You''d need this: (7) ''printf \''\\n\'''' Given (7), puppet will give (8) to bash: (8) printf ''\n'' and bash will give to exec(): (9) printf \n Make sense? -- 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.
How about using the alternate single quotes in ruby %q{string string string} Max On 11/21/11, Phil Frost <indigo@bitglue.com> wrote:> On 11/21/2011 01:30 AM, Douglas Garstang wrote: >> Grrr. I have the exec{} below in my puppet module. How do I escape the >> \ characters? I''ve tried every possible combination I can think of. >> I''ve used one, I''ve used two, and I''ve used THREE \. >> >> exec { >> ''oracle-extract-part'': >> command => "/usr/bin/printf >> \"n\np\n2\n2091\n+16384M\nw\n\" | /sbin/fdisk /dev/xvdj", >> unless => "/bin/cat /proc/partitions | /bin/grep >> ${orcl_ephm_device}2"; >> } > > Sounds like you need to use FOUR. Say you wanted to use printf to print > a newline. You would run this: > > (1) printf \n > > But, the backslash has special meaning in bash (or most shells). If you > type that in bash, you have to escape it, one of these ways: > > (2) printf \\n > (3) printf ''\n'' > > Puppet runs commands through a shell. So, you will have to apply > escaping appropriate for whatever shell is in use. > > But, the command is also in a string. Backslashes have special meaning > in puppet strings. So, we know the command we want to give to bash is: > > (4) printf \\n > > To put that in a puppet string we need to escape the \: > > (5) "printf \\\\n" > > If you don''t like all the backslashes, you could give single quotes to bash: > > (6) "printf ''\\n''" > > This is example 3, quoted with puppet''s rules. You could also use single > quotes in Puppet, but Puppet''s single-quote strings still find special > meaning in \, so it doesn''t really get you anything, and if you are > using single quotes for bash it''s actually worse. You''d need this: > > (7) ''printf \''\\n\'''' > > Given (7), puppet will give (8) to bash: > > (8) printf ''\n'' > > and bash will give to exec(): > > (9) printf \n > > Make sense? > > -- > 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. > >-- 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.
Zitat von Max Schubert <max.schubert@gmail.com>:> How about using the alternate single quotes in ruby > > %q{string string string}puppet manifests are not ruby code. ~pete -- 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.
Right - forgot that :). Maybe support for an alternate quoting operator should be added. On 11/21/11, Peter Meier <peter.meier@immerda.ch> wrote:> Zitat von Max Schubert <max.schubert@gmail.com>: > >> How about using the alternate single quotes in ruby >> >> %q{string string string} > > puppet manifests are not ruby code. > > ~pete > > -- > 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. > >-- 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.
I placed the printf string in a separate variabe, then I can double quote the variable and it will take care of escaping correctly. $fdisk_cmd = "c\nu\nn\np\n1\n\n\nw\n" exec { "fdisk /dev/${name}": command => "printf \"$fdisk_cmd\" | fdisk /dev/${name}", unless => "cat /proc/partitions | grep ${name}1", path => ''/sbin:/bin:/usr/bin'', } -- 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.