shell_out() without { default_env: false } param causes pecl install to fail
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 454
- Forks
- 480
- Avg merge
- 5h 35m
- Merged PRs (30d)
- 1
Description
👻 (Not A) Brief Description
When trying to install PHP7.2 from SCL on CentOS 7, installing a pecl package (imagick for example) using the php_pear resource fails because the dependencies cannot be found even when they are installed. But SSH-ing into the machine and running pecl install imagick via command line, runs without issue.
I think I've narrowed down the problem to the usage of shell_out() and how it handles the PATH environment variable. Calling it without the { default_env: false } flag causes the chef-client to inject /opt/chef/embedded/bin to the beginning of the $PATH so that when command runs, it picks up the pkg-config embedded in Chef instead of the one installed on the system.
Calling shell_out() without the flag: checking for pkg-config... /opt/chef/embedded/bin/pkg-config
Calling shell_out() with the flag: checking for pkg-config... /usr/bin/pkg-config
I can't figure out why it works without problems when using the default php version installed by CentOS, but either way I think that php_pear should explicitly tell chef-client to not muck with $PATH for consistency. Even the execute resource uses this flag to have the output match what you would see if you were to run it manually via command line (See: https://github.com/chef/chef/blob/master/lib/chef/resource/execute.rb#L72).
I'm not sure if this would break for other platforms, but it seems to work fine when updating calls to shell_out() to include this flag. Example below:
def pear_shell_out(command)
p = shell_out!(command, { default_env: false })
# pear/pecl commands return a 0 on failures...we'll grep for it
p.invalid! if p.stdout.split('\n').last =~ /^ERROR:.+/i
p
end
For reference:
- Unrelated, but similar issue: https://github.com/chef/chef/issues/5331
- Another unrelated, but similar: https://github.com/chef/chef/issues/6239
- Chef release notes (v14.2) about default_env: https://github.com/chef/chef/blob/a7938b8af1892438223f7bb468697d7097fe67a1/RELEASE_NOTES.md#default_env-property-in-execute-resource
🥞 Cookbook version
7.0.0
👩🍳 Chef-Infra Version
Chef 14.2+
EDIT (2020-02-20):
I'm not sure how to comment further so I'm making an edit here...
Sorry, I wasn't clear. The default_env flag is true by default in Chef 14. The fix that I suggested is to modify the pear_shell_out() method (https://github.com/sous-chefs/php/blob/master/resources/pear.rb#L187) to call shell_out()! with { default_env: false } flag.
The problem only occurs when using a PHP version provided in SCL (e.g.: CentOS 7 running PHP7.2 from SCL). In order to install PHP7.2 I've overridden a lot of the default attributes.
Overrides for reference:
override['php']['packages'] = %w(rh-php72 rh-php72-php-devel rh-php72-php-json rh-php72-php-ldap rh-php72-php-mbstring rh-php72-php-mysqlnd rh-php72-php-opcache rh-php72-php-pdo rh-php72-php-xml)
override['php']['pear'] = '/opt/rh/rh-php72/root/bin/pear'
override['php']['conf_dir'] = '/etc/opt/rh/rh-php72'
override['php']['ext_conf_dir'] = '/etc/opt/rh/rh-php72/php.d'
override['php']['ext_dir'] = '/opt/rh/rh-php72/root/usr/lib64/php/modules'
override['php']['fpm_package'] = 'rh-php72-php-fpm'
override['php']['fpm_pooldir'] = '/etc/opt/rh/rh-php72/php-fpm.d'
override['php']['fpm_default_conf'] = '/etc/opt/rh/rh-php72/php-fpm.d/www.conf'
override['php']['fpm_service'] = 'rh-php72-php-fpm'
To be clear, when using the default PHP that is provided by CentOS 7 (i.e.: without using SCL), there are no issues. I've tested the fix and it works fine for my use case, but I'm not sure if it will break on other platforms.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading resources/pear.rb, especially pear_shell_out, and compare its shell_out! invocation with the execute resource behavior described in the issue. Reproduce the pecl install failure with PHP 7.2 from CentOS SCL, then verify that the resource works with the system pkg-config without regressing default CentOS PHP behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100