exec GIT Variable PS1

58 views
Skip to first unread message

MaTi Villagra

unread,
Dec 11, 2012, 11:18:45 AM12/11/12
to puppet...@googlegroups.com
Hello I'm trying to push PS1 variable at .bashrc file 

    exec { 'GIT PS1 Variable':
    cwd => '/home/developer/.bashrc',
    command => '/bin/echo "PS1='[\u@\h \W\$(__git_ps1  " \"" (%s)"\"")]\$ ' " >> /home/developer/.bashrc',
    user => developer,
    group => developer,
   }

But client side  I get 

Dec 11 10:15:43 glb7240 puppet-agent[19762]: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at '['; expected ']' at /etc/puppet/modules/defaults/manifests/bash-extras.pp:53

If I copy command it work perfectly. Any toughs  ? 


Thanks. Appreciate. 





Roman Shaposhnik

unread,
Dec 11, 2012, 11:29:55 AM12/11/12
to puppet...@googlegroups.com
On Tue, Dec 11, 2012 at 8:18 AM, MaTi Villagra <mativi...@gmail.com> wrote:
> Hello I'm trying to push PS1 variable at .bashrc file
>
> exec { 'GIT PS1 Variable':
> cwd => '/home/developer/.bashrc',
> command => '/bin/echo "PS1='[\u@\h \W\$(__git_ps1 " \"" (%s)"\"")]\$ '

The single quote following PS1= closes the string and the next character
puppet parser sees is [ -- that's what it seems to complain about.

Thanks,
Roman.

Luke Bigum

unread,
Dec 11, 2012, 11:30:19 AM12/11/12
to puppet...@googlegroups.com
On Tuesday, December 11, 2012 4:18:45 PM UTC, MaTi Villagra wrote:
Hello I'm trying to push PS1 variable at .bashrc file 

    exec { 'GIT PS1 Variable':
    cwd => '/home/developer/.bashrc',
    command => '/bin/echo "PS1='[\u@\h \W\$(__git_ps1  " \"" (%s)"\"")]\$ ' " >> /home/developer/.bashrc',
    user => developer,
    group => developer,
   }

You're using single quotes for your Puppet string, but you've got single quotes in your bash PS1 line as well, so it's confusing the Puppet parser. You've got a single quote after the " [ ", so Puppet is probably interpreting the rest of the line as an array, which is why the error is complaining about a missing " ] ".

This function might help you get your escaping correct: 

MaTi Villagra

unread,
Dec 11, 2012, 1:09:32 PM12/11/12
to puppet...@googlegroups.com
Thanks for the help.  PS1 is confusing puppet parser as Luke suggest, 

For example I was trying to start from a single command like 

 command => "echo PS1='a' >> /home/developer/.bashrc" 

works perfectly. 

I also try to define as a line with no luck using http://projects.puppetlabs.com/projects/1/wiki/simple_text_patterns 


  line { 'PS1 git variable':
    file => '/home/developer/.bashrc',
    line => "PS1='[\u@\h \W\$(__git_ps1  " \"" (%s)"\"")]\$ ' ",
    ensure => present,

   }

Thanks! 

Jakov Sosic

unread,
Dec 11, 2012, 8:40:43 PM12/11/12
to puppet...@googlegroups.com
First of all, cwd points to a file in your case and not to a directory.

Next, you should escape quote characters, so if u use singlequote (') in
a puppet, which you should, then any occurrence of singlequote inside
your intended string should be escaped. So, your resource should look
like this:

exec { 'GIT PS1 Variable':
cwd => '/home/developer',
command => '/bin/echo "PS1=\'[\u@\h \W\$(__git_ps1 " \""
(%s)"\"")]\$ \' " >> /home/developer/.bashrc',
user => developer,
group => developer,
}


Note the escape (\) character in:

"PS1=\'

and:

$ \' " >>



--
Jakov Sosic
www.srce.unizg.hr

MaTi Villagra

unread,
Dec 12, 2012, 9:26:32 AM12/12/12
to puppet...@googlegroups.com
Jakov, yours suggestion works perfectly. 

The only thing missing is that exec will write the only every time puppet parser goes by. 

So I will code a onlyif condition under that exec. 

I will poste the final result here. 

Thanks! 

El martes, 11 de diciembre de 2012 10:18:45 UTC-6, MaTi Villagra escribió:
Reply all
Reply to author
Forward
0 new messages