shell, # for grep un" /> shell, # for grep un" /> shell, # for grep un"/>

shell built-ins fail in exec statement

119 Views Asked by At

I have the following exec statement:

exec { 'enable-locale':                                                  
  command  => 'sed -i "/^#en_US.*/s/^#//" /etc/locale.gen',                 
  provider => shell,  # for grep                                            
  unless   => 'locale -a | grep -i en_US.utf8',                             
  path     => '/usr/bin',                                                   
}

Which returns the following error:

Error: /Stage[main]/Qdii::Base/Exec[enable-locale]: Could not evaluate: /bin/sh: 1: grep: not found

I find this curious, as the same shell command works fine:

$ /bin/sh -c 'locale -a | grep -i en_US.utf8'
en_US.utf8
1

There are 1 best solutions below

3
qdii On

Confusingly, while grep is sometimes a builtin, in the case of Ubuntu it isn't.

/bin/sh -c 'which grep'
/bin/grep

The fix is to add the /bin/ path to the path argument of the exec statement.