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

macos_userdefaults cannot manage an array value idempotently. #10084

Closed
natewalck opened this issue Jun 30, 2020 · 1 comment · Fixed by #10118
Closed

macos_userdefaults cannot manage an array value idempotently. #10084

natewalck opened this issue Jun 30, 2020 · 1 comment · Fixed by #10118

Comments

@natewalck
Copy link
Contributor

Description

When setting an array as a value for a key using macos_userdefaults, chef will set the array every chef run.

Chef Version

16.2.50

Platform Version

10.16 (but probably <= 10.15 as well)

Replication Case

Attempt to set an array as a value for a key using macos_userdefaults

Client Output

Nothing relevant. Run chef 2-3 times, it will set the key every run as the idempotence check isn't working correctly.

@natewalck natewalck added the Status: Untriaged An issue that has yet to be triaged. label Jun 30, 2020
@erikng
Copy link
Contributor

erikng commented Jun 30, 2020

This is also related to #10075 and #10083

putting some debug prints in the macos_userdefaults

defaults read '/Library/Preferences/ManagedInstalls' 'AdditionalHttpHeaders' | grep -qx '["Authorization: Basic basdadfsdfwsdfswdfwerf=="]'
      * execute[defaults write '/Library/Preferences/ManagedInstalls' 'AdditionalHttpHeaders' -array 'Authorization: Basic basdadfsdfwsdfswdfwerf=='] action run

the grep is wrong, so it returns nothing.

chef is running

defaults read '/Library/Preferences/ManagedInstalls' 'AdditionalHttpHeaders' | grep -qx '["Authorization: Basic basdadfsdfwsdfswdfwerf=="]' 

$?
zsh: command not found: 1
defaults read '/Library/Preferences/ManagedInstalls' 'AdditionalHttpHeaders'                                                                                           
(
    "Authorization: Basic basdadfsdfwsdfswdfwerf=="
)

This is going to be very ugly to unpack (and why using CFPreferences API over defaults read is better) but one potential solution (that likely will not work with more advanced arrays):

defaults read '/Library/Preferences/ManagedInstalls' 'AdditionalHttpHeaders' | grep -qx '    "Authorization: Basic basdadfsdfwsdfswdfwerf=="'
$?
zsh: command not found: 0

The command above takes off the [] since that's not a format that defaults read uses and adds four spaces. This then allows the line to return correctly.

I would recommend against ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants