Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

value_for_platform: boolean value not working when default value is set to "true" #8704

Open
nicutor opened this issue Jul 2, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@nicutor
Copy link

commented Jul 2, 2019

Description

value_for_platform works with string and arrays, and in some cases with booleans, but, when "default" value is set to "true", the specific OS versions values are ignored.

Chef Version

Chef Infra Client: 15.0.300
Chef: 14.2.0
Chef: 13.4.24

Platform Version

I've tested this on Debian 7/8/9, Ubuntu 12/14/16/18 and CentOS 6/7 each one of them with their specific chef latest version.

Replication Case

attributes/test.rb

default['test']['vfp_boolean'] = value_for_platform(
  ['centos'] => {
    '~> 7.0' => false,
    'default' => true },
  ['debian'] => {
    '~> 8' => false,
    'default' => true },
  ['ubuntu'] => {
    '~> 16.04' => false,
    'default' => true }
)

default['test']['vfp_string'] = value_for_platform(
  ['centos'] => {
    '~> 7.0' => 'string',
    'default' => 'string_default' },
  ['debian'] => {
    '~> 8' => 'string',
    'default' => 'string_default' },
  ['ubuntu'] => {
    '~> 16.04' => 'string',
    'default' => 'string_default' }
)

default['test']['vfp_array'] = value_for_platform(
  ['centos'] => {
    '~> 7.0' => ['array'],
    'default' => ['array_default'] },
  ['debian'] => {
    '~> 8' => ['array'],
    'default' => ['array_default'] },
  ['ubuntu'] => {
    '~> 16.04' => ['array'],
    'default' => ['array_default'] }
)

recipes/test.rb

if node['test']['vfp_boolean']
  puts "Test boolean: true"
else
  puts "Test boolean: false"
end
puts "Test boolean to string: #{node['test']['vfp_boolean'].to_s}"
puts "Test string: #{node['test']['vfp_string']}"
puts "Test array: #{node['test']['vfp_array']}"

Client Output

The output is from CentOS 7 and the boolean result should be "false" but the default value is returned instead.

Test boolean: true
Test boolean to string: true
Test string: string
Test array: ["array"]

Temporary fix

If the default value is not set at all, and there are only specific OS versions values, then, everything works:

default['test']['vfp_boolean'] = value_for_platform(
  ['centos'] => {
    '~> 7.0' => false,
    '~> 6.0' => true },
...

Output:

Test boolean: false
Test boolean to string:
Test string: string
Test array: ["array"]

However, the "boolean to string" value is empty. It should return "false", probabil is nil or such, and that's why the default value is returned instead.

Maybe I am missing something and there is another way to use value_for_platform, but I didn't found anything else on docs, so I guess is a bug.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.