0

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
qdii
  • 12,505
  • 10
  • 59
  • 116

1 Answers1

0

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.

qdii
  • 12,505
  • 10
  • 59
  • 116
  • 1
    That a utility is installed in `/bin` does not convey a sense of being any more "builtin" than if it were installed in `/usr/bin`. The most applicable meaning of that term I can think of at the moment is for utilities that are provided directly by the shell, as opposed to or in addition to as separate binaries. The `test`, `echo`, and `kill` utilities are examples that may be either builtin or external (or both). – John Bollinger Dec 29 '19 at 18:43
  • But yes, there is some inconsistency as to where various standard utilities are installed on different Unixen, and even on different Linuxes. – John Bollinger Dec 29 '19 at 18:45
  • @JohnBollinger I actually mistakenly assumed grep was a shell built-in, just like `if`, etc. That was my own mistake. – qdii Dec 31 '19 at 10:22