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

Migrate to native Chef helper functions #268

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_applocker/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# limitations under the License.
#

return unless node.windows?
return unless windows?

cpe_applocker 'Uninstall Applocker' do
not_if { node['cpe_applocker']['enabled'].nil? }
Expand Down
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_bluetooth/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
# Cookbook Name:: cpe_bluetooth
# Recipes:: default

return unless node.macos?
return unless macos?
cpe_bluetooth 'Configure Bluetooth Profile'
20 changes: 10 additions & 10 deletions itchef/cookbooks/cpe_chrome/resources/cpe_chrome_posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

action_class do
def install_repos
return unless node.linux?
return unless linux?
return unless node['cpe_chrome']['manage_repo']

yum_repository 'google-chrome' do
only_if { node.fedora? || node.centos? }
only_if { fedora? || centos? }
description 'Google Chrome repo'
baseurl 'http://dl.google.com/linux/chrome/rpm/stable/x86_64'
enabled true
Expand All @@ -42,7 +42,7 @@ def install_repos
end

apt_repository 'google-chrome' do
only_if { node.debian_family? }
only_if { debian? }
uri 'http://dl.google.com/linux/chrome/deb/'
distribution 'stable'
components ['main']
Expand All @@ -53,12 +53,12 @@ def install_repos
end

def install_chrome
return unless node.linux?
return unless linux?
return unless node['cpe_chrome']['install_package']

package 'google-chrome-stable' do
only_if do
node.fedora? || node.centos? || node.debian_family?
fedora? || centos? || debian?
end
action :upgrade
end
Expand Down Expand Up @@ -111,14 +111,14 @@ def manage_chrome_linux(mprefs, prefs)
directory path do
mode '0755'
owner node.root_user
group node.root_group
group node['root_group']
end
end
migrate_chromium_settings_linux
link '/etc/chromium' do
to '/etc/opt/chrome'
owner node.root_user
group node.root_group
group node['root_group']
end
{
'/etc/opt/chrome/policies/managed/test_policy.json' => prefs,
Expand All @@ -132,7 +132,7 @@ def manage_chrome_linux(mprefs, prefs)
file path do
mode '0644'
owner node.root_user
group node.root_group
group node['root_group']
action :create
content Chef::JSONCompat.to_json_pretty(preferences)
end
Expand Down Expand Up @@ -303,7 +303,7 @@ def manage_chrome_extensions_linux(extprefs)
file path do
mode '0644'
owner node.root_user
group node.root_group
group node['root_group']
action :create
content Chef::JSONCompat.to_json_pretty(extension_hash)
end
Expand All @@ -321,7 +321,7 @@ def migrate_chromium_settings_linux
code <<-EOH
find /etc/chromium -type d -exec chmod 0755 {} \\;
find /etc/chromium -type f -exec chmod 0644 {} \\;
chown -R #{node.root_user}:#{node.root_group} /etc/chromium
chown -R #{node.root_user}:#{node['root_group']} /etc/chromium
cp -R /etc/chromium/* /etc/opt/chrome/
rm -rf /etc/chromium
EOH
Expand Down
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_dconf/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
# Cookbook Name:: cpe_dconf
# Recipe:: default

return unless node.linux?
return unless linux?

cpe_dconf 'Configure dconf settings'
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
# Cookbook Name:: cpe_deprecation_notifier
# Recipe:: default

return unless node.macos?
return unless macos?

cpe_deprecation_notifier 'Managed Deprecation Notifier'
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_flatpak/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# limitations under the License.
#

return unless node.linux?
return unless linux?

cpe_flatpak 'Manage Flatpak'
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_gnome_software/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
# Cookbook Name:: cpe_gnome_software
# Recipe:: default

return unless node.fedora?
return unless fedora?

cpe_gnome_software 'Configure GNOME Software'
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
default_action :manage

action :manage do
unless node.fedora?
unless fedora?
fail 'cpe_gnome_software is only supported on Fedora'
end

Expand Down
8 changes: 4 additions & 4 deletions itchef/cookbooks/cpe_hosts/resources/cpe_hosts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
file HOSTS_FILE do
retries 2
ignore_failure true
unless node.windows?
unless windows?
owner node.root_user
group node.root_group
group node['root_group']
mode '0644'
end
content lines.join
Expand All @@ -61,9 +61,9 @@
retries 2
ignore_failure true
source 'hosts.erb'
unless node.windows?
unless windows?
owner node.root_user
group node.root_group
group node['root_group']
mode '0644'
end
end
Expand Down
8 changes: 4 additions & 4 deletions itchef/cookbooks/cpe_init/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
]

# Unix-like platforms only
unless node.windows?
unless windows?
run_list += [
'cpe_logger',
'cpe_pathsd',
'cpe_symlinks',
]
end

if node.macos?
if macos?
run_list += [
'cpe_bluetooth',
'cpe_deprecation_notifier',
Expand All @@ -54,12 +54,12 @@
'cpe_launchd',
'cpe_profiles',
]
elsif node.windows?
elsif windows?
run_list += [
'cpe_applocker',
'cpe_win_telemetry',
]
elsif node.linux?
elsif linux?
run_list += [
'cpe_dconf',
'cpe_flatpak',
Expand Down
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_kernel_channel/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Cookbook Name:: cpe_dconf
# Recipe:: default

return unless node.fedora?
return unless fedora?

cpe_kernel_channel 'Configure kernel channel' do
only_if { node['cpe_kernel_channel']['enable'] }
Expand Down
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_launchd/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Cookbook Name:: cpe_launchd
# Recipes:: default

return unless node.macos?
return unless macos?

cpe_launchd 'Managing all of launchd'

Expand Down
10 changes: 5 additions & 5 deletions itchef/cookbooks/cpe_logger/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@
# Cookbook Name:: cpe_logger
# Recipes:: default

return if node.windows?
return if windows?

logfile = '/var/log/cpe_logger.log'
logrotate_conf = if node.macos?
logrotate_conf = if macos?
'/etc/newsyslog.d/cpe_logger.conf'
elsif node.linux?
elsif linux?
'/etc/logrotate.d/cpe_logger.conf'
end

return if logrotate_conf.nil?

package 'logrotate' do
only_if { node['cpe_logger']['enable'] }
only_if { node.linux? }
only_if { linux? }
action :upgrade
end

template logrotate_conf do
only_if { node['cpe_logger']['enable'] }
source "logrotate.#{node['os']}.erb"
owner node.root_user
group node.root_group
group node['root_group']
mode '0644'
variables(
:logfile => logfile,
Expand Down
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_munki/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Cookbook Name:: cpe_munki
# Recipe:: default

return unless node.macos?
return unless macos?

cpe_munki_install 'Install Munki'
cpe_munki_local 'Manage Local Munki Manifest'
Expand Down
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_nomad/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
# limitations under the License.
#

return unless node.macos?
return unless macos?

cpe_nomad_darwin 'Configure NoMAD'
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_pathsd/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Cookbook Name:: cpe_pathsd
# Recipe:: default

return if node.windows?
return if windows?

cpe_pathsd 'Manage paths' do
only_if { node['cpe_pathsd'].any? }
Expand Down
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_powermanagement/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
# limitations under the License.
#

return unless node.macos?
return unless macos?

cpe_powermanagement 'Configure Power Management Profile'
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_preferencepanes/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
# Cookbook Name:: cpe_preferencepanes
# Recipe:: default

return unless node.macos?
return unless macos?
cpe_preferencepanes 'Configure PreferencePanes Profile'
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_profiles/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
# Cookbook Name:: cpe_profiles
# Recipe:: default

return unless node.macos?
return unless macos?

cpe_profiles 'Managing Configuration Profiles'
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_profiles_local/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Cookbook Name:: cpe_profiles_local
# Recipe:: default

return unless node.macos?
return unless macos?

cpe_profiles_local 'Managing all Configuration Profiles'

Expand Down
14 changes: 7 additions & 7 deletions itchef/cookbooks/cpe_remote/resources/zip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
recursive true
end

if node.windows?
if windows?
zip_cmd = CPE::Utils.sevenzip_cmd
return if CPE::Log.if(
"#{cookbook_name}: No local 7zip command found",
Expand Down Expand Up @@ -116,9 +116,9 @@
headers node['cpe_remote']['additional_headers']
end
action :create
notifies :install, 'package[unzip]', :immediately if node.linux?
notifies :run, 'execute[extract_zip]' unless node.windows?
if node.windows?
notifies :install, 'package[unzip]', :immediately if linux?
notifies :run, 'execute[extract_zip]' unless windows?
if windows?
owner 'Administrators'
group 'Administrators'
notifies :create, 'directory[dest_folder]'
Expand All @@ -127,21 +127,21 @@
end

package 'unzip' do # ~FB043
only_if { node.linux? }
only_if { linux? }
action :nothing
end

execute 'extract_zip' do
only_if { ::File.exist?(zip_path) }
not_if { node.windows? }
not_if { windows? }
cwd new_resource.extract_location
command "unzip -o #{zip_path} -d #{new_resource.extract_location}"
action :nothing
end

# @lint-ignore FBCHEFFoodcritic
directory new_resource.extract_location do # ~FB019
not_if { node.windows? }
not_if { windows? }
recursive true
mode new_resource.mode
owner new_resource.owner
Expand Down
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_symlinks/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
# Cookbook Name:: cpe_symlinks
# Recipe:: default

return if node.windows?
return if windows?
cpe_symlinks 'Manage symlinks'
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_symlinks/resources/cpe_symlinks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
content Chef::JSONCompat.to_json_pretty(symlink_list.uniq)
action :create
owner node.root_user
group node.root_group
group node['root_group']
mode '755'
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

# Copy this file and rename it to your username (e.g. nate.rb)
# Always scope the change to the OS you are targeting
if node.macos?
if macos?
end
2 changes: 1 addition & 1 deletion itchef/cookbooks/cpe_win_telemetry/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
# Cookbook Name:: cpe_win_telemetry
# Recipe:: default

return unless node.windows? && node.os_at_least?('10.0.15063')
return unless windows? && node.os_at_least?('10.0.15063')
cpe_win_telemetry 'Configure Windows Telemetry Settings'
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
provides :cpe_win_telemetry, :os => 'windows'

action :config do
return unless node.windows? && node.os_at_least?('10.0.15063')
return unless windows? && node.os_at_least?('10.0.15063')
if node['cpe_win_telemetry']['AllowTelemetry'] == -1
['DiagTrack', 'dmwappushservice'].each do |svc_name|
# Disable these services to kill telemetry data to Microsoft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
# Cookbook Name:: cpe_windows_update_for_business
# Recipe:: default

return unless node.windows? && !node.os_less_than?('10.0.15063')
return unless windows? && !node.os_less_than?('10.0.15063')

cpe_windows_update_for_business 'Configure Windows Update for Business'
Loading