chef 17.7.22 → 17.9.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/lib/chef/application/base.rb +1 -1
  4. data/lib/chef/application/exit_code.rb +7 -21
  5. data/lib/chef/compliance/default_attributes.rb +12 -2
  6. data/lib/chef/compliance/runner.rb +51 -5
  7. data/lib/chef/cookbook/syntax_check.rb +1 -1
  8. data/lib/chef/cookbook_version.rb +1 -1
  9. data/lib/chef/mixin/powershell_exec.rb +6 -5
  10. data/lib/chef/mixin/why_run.rb +8 -2
  11. data/lib/chef/powershell.rb +8 -6
  12. data/lib/chef/provider/cron.rb +2 -2
  13. data/lib/chef/provider/directory.rb +2 -2
  14. data/lib/chef/provider/ifconfig.rb +5 -5
  15. data/lib/chef/provider/mount/linux.rb +16 -2
  16. data/lib/chef/provider/mount/mount.rb +1 -1
  17. data/lib/chef/provider/package/dnf.rb +1 -1
  18. data/lib/chef/provider/package/habitat.rb +1 -1
  19. data/lib/chef/provider/package/powershell.rb +13 -10
  20. data/lib/chef/provider/package/yum/python_helper.rb +81 -25
  21. data/lib/chef/provider/package/yum.rb +39 -12
  22. data/lib/chef/provider/package/zypper.rb +2 -0
  23. data/lib/chef/provider/package.rb +63 -28
  24. data/lib/chef/provider/user/mac.rb +3 -3
  25. data/lib/chef/provider.rb +5 -2
  26. data/lib/chef/providers.rb +0 -1
  27. data/lib/chef/pwsh.rb +3 -2
  28. data/lib/chef/resource/apt_package.rb +2 -2
  29. data/lib/chef/resource/chef_client_config.rb +21 -1
  30. data/lib/chef/resource/chef_client_launchd.rb +1 -1
  31. data/lib/chef/resource/chef_client_trusted_certificate.rb +1 -0
  32. data/lib/chef/resource/chocolatey_package.rb +3 -3
  33. data/lib/chef/resource/cron/cron.rb +75 -1
  34. data/lib/chef/resource/cron/cron_d.rb +2 -1
  35. data/lib/chef/resource/dnf_package.rb +4 -6
  36. data/lib/chef/resource/dpkg_package.rb +5 -0
  37. data/lib/chef/resource/execute.rb +1 -4
  38. data/lib/chef/resource/habitat/habitat_sup.rb +1 -1
  39. data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
  40. data/lib/chef/resource/habitat_install.rb +2 -2
  41. data/lib/chef/resource/homebrew_tap.rb +1 -5
  42. data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
  43. data/lib/chef/resource/launchd.rb +2 -5
  44. data/lib/chef/resource/macos_userdefaults.rb +25 -30
  45. data/lib/chef/resource/powershell_package_source.rb +8 -8
  46. data/lib/chef/resource/remote_file.rb +1 -1
  47. data/lib/chef/resource/rhsm_register.rb +31 -0
  48. data/lib/chef/resource/support/client.erb +7 -0
  49. data/lib/chef/resource/windows_feature_powershell.rb +8 -9
  50. data/lib/chef/resource/windows_task.rb +25 -10
  51. data/lib/chef/resource.rb +3 -3
  52. data/lib/chef/resource_reporter.rb +1 -1
  53. data/lib/chef/run_lock.rb +1 -1
  54. data/lib/chef/secret_fetcher/azure_key_vault.rb +4 -2
  55. data/lib/chef/secret_fetcher/hashi_vault.rb +37 -3
  56. data/lib/chef/version.rb +1 -1
  57. data/spec/functional/resource/dnf_package_spec.rb +138 -124
  58. data/spec/functional/resource/dpkg_package_spec.rb +16 -0
  59. data/spec/functional/resource/macos_userdefaults_spec.rb +21 -1
  60. data/spec/functional/resource/yum_package_spec.rb +789 -129
  61. data/spec/functional/resource/zypper_package_spec.rb +7 -0
  62. data/spec/integration/client/client_spec.rb +31 -0
  63. data/spec/spec_helper.rb +3 -3
  64. data/spec/support/platform_helpers.rb +1 -1
  65. data/spec/support/ruby_installer.rb +1 -1
  66. data/spec/support/shared/functional/file_resource.rb +1 -1
  67. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +1 -1
  68. data/spec/unit/application/base_spec.rb +40 -0
  69. data/spec/unit/compliance/runner_spec.rb +62 -1
  70. data/spec/unit/dsl/registry_helper_spec.rb +6 -6
  71. data/spec/unit/file_access_control_spec.rb +1 -1
  72. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +1 -1
  73. data/spec/unit/lwrp_spec.rb +2 -2
  74. data/spec/unit/mixin/why_run_spec.rb +53 -0
  75. data/spec/unit/provider/dsc_script_spec.rb +8 -8
  76. data/spec/unit/provider/group/groupadd_spec.rb +1 -0
  77. data/spec/unit/provider/group/usermod_spec.rb +4 -4
  78. data/spec/unit/provider/ifconfig/aix_spec.rb +14 -14
  79. data/spec/unit/provider/ifconfig/debian_spec.rb +1 -1
  80. data/spec/unit/provider/ifconfig/redhat_spec.rb +1 -1
  81. data/spec/unit/provider/ifconfig_spec.rb +5 -3
  82. data/spec/unit/provider/mount/linux_spec.rb +16 -3
  83. data/spec/unit/provider/package/bff_spec.rb +1 -0
  84. data/spec/unit/provider/package/powershell_spec.rb +114 -114
  85. data/spec/unit/provider/package/rubygems_spec.rb +3 -0
  86. data/spec/unit/provider/package/solaris_spec.rb +1 -0
  87. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +3 -3
  88. data/spec/unit/provider/service/arch_service_spec.rb +2 -2
  89. data/spec/unit/provider/service/debian_service_spec.rb +1 -0
  90. data/spec/unit/provider/service/gentoo_service_spec.rb +3 -2
  91. data/spec/unit/provider/service/macosx_spec.rb +1 -0
  92. data/spec/unit/provider/service/redhat_spec.rb +4 -1
  93. data/spec/unit/provider/service/simple_service_spec.rb +6 -4
  94. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  95. data/spec/unit/provider/user_spec.rb +2 -0
  96. data/spec/unit/resource/chef_client_trusted_certificate_spec.rb +14 -0
  97. data/spec/unit/resource/conditional_spec.rb +4 -4
  98. data/spec/unit/resource/dpkg_package_spec.rb +12 -0
  99. data/spec/unit/resource/macos_user_defaults_spec.rb +1 -1
  100. data/spec/unit/resource/rhsm_register_spec.rb +42 -0
  101. data/spec/unit/resource_spec.rb +2 -2
  102. data/spec/unit/secret_fetcher/hashi_vault_spec.rb +46 -0
  103. metadata +9 -9
  104. data/lib/chef/provider/group/suse.rb +0 -82
  105. data/spec/unit/provider/group/suse_spec.rb +0 -90
@@ -20,6 +20,7 @@
20
20
  require_relative "../../resource"
21
21
  require_relative "../helpers/cron_validations"
22
22
  require_relative "../../provider/cron" # do not remove. we actually need this below
23
+ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
23
24
 
24
25
  class Chef
25
26
  class Resource
@@ -30,7 +31,80 @@ class Chef
30
31
 
31
32
  provides :cron
32
33
 
33
- description "Use the **cron** resource to manage cron entries for time-based job scheduling. Properties for a schedule will default to * if not provided. The cron resource requires access to a crontab program, typically cron."
34
+ description "Use the **cron** resource to manage cron entries for time-based job scheduling. Properties for a schedule will default to * if not provided. The cron resource requires access to a crontab program, typically cron. Warning: The cron resource should only be used to modify an entry in a crontab file. The `cron_d` resource directly manages `cron.d` files. This resource ships in #{ChefUtils::Dist::Infra::PRODUCT} 14.4 or later and can also be found in the [cron](https://github.com/chef-cookbooks/cron) cookbook) for previous #{ChefUtils::Dist::Infra::PRODUCT} releases."
35
+
36
+ examples <<~'DOC'
37
+ **Run a program at a specified interval**
38
+
39
+ ```ruby
40
+ cron 'noop' do
41
+ hour '5'
42
+ minute '0'
43
+ command '/bin/true'
44
+ end
45
+ ```
46
+
47
+ **Run an entry if a folder exists**
48
+
49
+ ```ruby
50
+ cron 'ganglia_tomcat_thread_max' do
51
+ command "/usr/bin/gmetric
52
+ -n 'tomcat threads max'
53
+ -t uint32
54
+ -v '/usr/local/bin/tomcat-stat --thread-max'"
55
+ only_if { ::File.exist?('/home/jboss') }
56
+ end
57
+ ```
58
+
59
+ **Run every Saturday, 8:00 AM**
60
+
61
+ The following example shows a schedule that will run every hour at 8:00 each Saturday morning, and will then send an email to “admin@example.com” after each run.
62
+
63
+ ```ruby
64
+ cron 'name_of_cron_entry' do
65
+ minute '0'
66
+ hour '8'
67
+ weekday '6'
68
+ mailto 'admin@example.com'
69
+ action :create
70
+ end
71
+ ```
72
+
73
+ **Run once a week**
74
+
75
+ ```ruby
76
+ cron 'cookbooks_report' do
77
+ minute '0'
78
+ hour '0'
79
+ weekday '1'
80
+ user 'chefio'
81
+ mailto 'sysadmin@example.com'
82
+ home '/srv/supermarket/shared/system'
83
+ command %W{
84
+ cd /srv/supermarket/current &&
85
+ env RUBYLIB="/srv/supermarket/current/lib"
86
+ RAILS_ASSET_ID=`git rev-parse HEAD` RAILS_ENV="#{rails_env}"
87
+ bundle exec rake cookbooks_report
88
+ }.join(' ')
89
+ action :create
90
+ end
91
+ ```
92
+
93
+ **Run only in November**
94
+
95
+ The following example shows a schedule that will run at 8:00 PM, every weekday (Monday through Friday), but only in November:
96
+
97
+ ```ruby
98
+ cron 'name_of_cron_entry' do
99
+ minute '0'
100
+ hour '20'
101
+ day '*'
102
+ month '11'
103
+ weekday '1-5'
104
+ action :create
105
+ end
106
+ ```
107
+ DOC
34
108
 
35
109
  state_attrs :minute, :hour, :day, :month, :weekday, :user
36
110
 
@@ -18,6 +18,7 @@
18
18
  require_relative "../../resource"
19
19
  require_relative "../helpers/cron_validations"
20
20
  require "shellwords" unless defined?(Shellwords)
21
+ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
21
22
 
22
23
  class Chef
23
24
  class Resource
@@ -29,7 +30,7 @@ class Chef
29
30
  provides :cron_d
30
31
 
31
32
  introduced "14.4"
32
- description "Use the **cron_d** resource to manage cron job files in the `/etc/cron.d` directory. This is similar to the 'cron' resource, but it does not use the monolithic /etc/crontab file."
33
+ description "Use the **cron_d** resource to manage cron job files in the `/etc/cron.d` directory. Warning: #{ChefUtils::Dist::Infra::PRODUCT} also ships with the **cron** resource for managing the monolithic `/etc/crontab` file on platforms that lack cron.d support. See the [cron resource](/resources/cron/) for information on using that resource."
33
34
  examples <<~DOC
34
35
  **Run a program on the fifth hour of the day**
35
36
 
@@ -68,12 +68,10 @@ class Chef
68
68
  end
69
69
  }
70
70
 
71
- def allow_downgrade(arg = nil)
72
- unless arg.nil?
73
- Chef.deprecated(:dnf_package_allow_downgrade, "the allow_downgrade property on the dnf_package provider is not used, DNF supports downgrades by default.")
74
- end
75
- true
76
- end
71
+ property :allow_downgrade, [ TrueClass, FalseClass ],
72
+ description: "Allow downgrading a package to satisfy requested version requirements.",
73
+ default: true,
74
+ desired_state: false
77
75
  end
78
76
  end
79
77
  end
@@ -37,6 +37,11 @@ class Chef
37
37
  property :response_file_variables, Hash,
38
38
  description: "A Hash of response file variables in the form of {'VARIABLE' => 'VALUE'}.",
39
39
  default: {}, desired_state: false
40
+
41
+ property :allow_downgrade, [ TrueClass, FalseClass ],
42
+ description: "Allow downgrading a package to satisfy requested version requirements.",
43
+ default: true,
44
+ desired_state: false
40
45
  end
41
46
  end
42
47
  end
@@ -346,7 +346,7 @@ class Chef
346
346
 
347
347
  By default, notifications are `:delayed`, that is they are queued up as they are
348
348
  triggered, and then executed at the very end of a Chef Infra Client run. To run
349
- kan action immediately, use `:immediately`:
349
+ an action immediately, use `:immediately`:
350
350
 
351
351
  ```ruby
352
352
  template '/etc/nagios3/configures-nagios.conf' do
@@ -517,9 +517,6 @@ class Chef
517
517
  name_property: true,
518
518
  description: "An optional property to set the command to be executed if it differs from the resource block's name. Note: Use the **execute** resource to run a single command. Use multiple **execute** resource blocks to run multiple commands."
519
519
 
520
- property :umask, [ String, Integer ],
521
- description: "The file mode creation mask, or umask."
522
-
523
520
  property :creates, String,
524
521
  description: "Prevent a command from creating a file when that file already exists."
525
522
 
@@ -284,7 +284,7 @@ class Chef
284
284
  if new_resource.peer
285
285
  peer_list = []
286
286
  new_resource.peer.each do |p|
287
- peer_list << if p !~ /.*:.*/
287
+ peer_list << if !/.*:.*/.match?(p)
288
288
  p + ":9632"
289
289
  else
290
290
  p
@@ -15,7 +15,7 @@
15
15
  # limitations under the License.
16
16
  #
17
17
 
18
- require "win32/service" if RUBY_PLATFORM =~ /mswin|mingw32|windows/
18
+ require "win32/service" if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
19
19
  require_relative "habitat_sup"
20
20
 
21
21
  class Chef
@@ -52,8 +52,8 @@ class Chef
52
52
  property :name, String, default: "install habitat",
53
53
  description: "Name of the resource block. This has no impact other than logging."
54
54
 
55
- property :install_url, String, default: "https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh",
56
- description: "URL to the install script, default is from the [habitat repo](https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh) ."
55
+ property :install_url, String, default: "https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.sh",
56
+ description: "URL to the install script, default is from the [habitat repo](https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.sh) ."
57
57
 
58
58
  property :bldr_url, String,
59
59
  description: "Optional URL to an alternate Habitat Builder."
@@ -41,10 +41,6 @@ class Chef
41
41
  property :url, String,
42
42
  description: "The URL of the tap."
43
43
 
44
- property :full, [TrueClass, FalseClass],
45
- description: "Perform a full clone on the tap, as opposed to a shallow clone.",
46
- default: false
47
-
48
44
  property :homebrew_path, String,
49
45
  description: "The path to the Homebrew binary.",
50
46
  default: "/usr/local/bin/brew"
@@ -57,7 +53,7 @@ class Chef
57
53
  action :tap, description: "Add a Homebrew tap." do
58
54
  unless tapped?(new_resource.tap_name)
59
55
  converge_by("tap #{new_resource.tap_name}") do
60
- shell_out!("#{new_resource.homebrew_path} tap #{new_resource.full ? "--full" : ""} #{new_resource.tap_name} #{new_resource.url || ""}",
56
+ shell_out!("#{new_resource.homebrew_path} tap #{new_resource.tap_name} #{new_resource.url || ""}",
61
57
  user: new_resource.owner,
62
58
  env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner },
63
59
  cwd: ::Dir.home(new_resource.owner))
@@ -135,7 +135,7 @@ class Chef
135
135
 
136
136
  action_class do
137
137
  def load_waiver_file_to_hash(file_name)
138
- if file_name =~ %r{(/|C:\\).*(.yaml|.yml)}i
138
+ if %r{(/|C:\\).*(.yaml|.yml)}i.match?(file_name)
139
139
  if ::File.exist?(file_name)
140
140
  hash = ::YAML.load_file(file_name)
141
141
  if hash == false || hash.nil? || hash == ""
@@ -84,7 +84,7 @@ class Chef
84
84
  end
85
85
 
86
86
  # Check to make sure that our array only has hashes
87
- unless array.all? { |obj| obj.is_a?(Hash) }
87
+ unless array.all?(Hash)
88
88
  error_msg = "start_calendar_interval must be a single hash or an array of hashes!"
89
89
  raise Chef::Exceptions::ValidationFailed, error_msg
90
90
  end
@@ -98,7 +98,7 @@ class Chef
98
98
  raise Chef::Exceptions::ValidationFailed, error_msg
99
99
  end
100
100
 
101
- unless entry.values.all? { |val| val.is_a?(Integer) }
101
+ unless entry.values.all?(Integer)
102
102
  failed_values = entry.values.reject { |val| val.is_a?(Integer) }.join(", ")
103
103
  error_msg = "Invalid value(s) (#{failed_values}) for start_calendar_interval item. Values must be integers!"
104
104
  raise Chef::Exceptions::ValidationFailed, error_msg
@@ -238,9 +238,6 @@ class Chef
238
238
  property :time_out, Integer,
239
239
  description: "The amount of time (in seconds) a job may be idle before it times out. If no value is specified, the default timeout value for launchd will be used."
240
240
 
241
- property :umask, Integer,
242
- description: "A decimal value to pass to `umask` before running a job."
243
-
244
241
  property :username, String,
245
242
  description: "When launchd is run as the root user, the user to run the job as."
246
243
 
@@ -17,6 +17,7 @@
17
17
 
18
18
  require_relative "../resource"
19
19
  require "chef-utils/dist" unless defined?(ChefUtils::Dist)
20
+ require "corefoundation" if RUBY_PLATFORM.match?(/darwin/)
20
21
  autoload :Plist, "plist"
21
22
 
22
23
  class Chef
@@ -80,8 +81,7 @@ class Chef
80
81
  property :host, [String, Symbol],
81
82
  description: "Set either :current, :all or a hostname to set the user default at the host level.",
82
83
  desired_state: false,
83
- introduced: "16.3",
84
- coerce: proc { |value| to_cf_host(value) }
84
+ introduced: "16.3"
85
85
 
86
86
  property :value, [Integer, Float, String, TrueClass, FalseClass, Hash, Array],
87
87
  description: "The value of the key. Note: With the `type` property set to `bool`, `String` forms of Boolean true/false values that Apple accepts in the defaults command will be coerced: 0/1, 'TRUE'/'FALSE,' 'true'/false', 'YES'/'NO', or 'yes'/'no'.",
@@ -95,8 +95,7 @@ class Chef
95
95
 
96
96
  property :user, [String, Symbol],
97
97
  description: "The system user that the default will be applied to. Set :current for current user, :all for all users or pass a valid username",
98
- desired_state: false,
99
- coerce: proc { |value| to_cf_user(value) }
98
+ desired_state: false
100
99
 
101
100
  property :sudo, [TrueClass, FalseClass],
102
101
  description: "Set to true if the setting you wish to modify requires privileged access. This requires passwordless sudo for the `/usr/bin/defaults` command to be setup for the user running #{ChefUtils::Dist::Infra::PRODUCT}.",
@@ -117,7 +116,7 @@ class Chef
117
116
  action :write, description: "Write the value to the specified domain/key." do
118
117
  converge_if_changed do
119
118
  Chef::Log.debug("Updating defaults value for #{new_resource.key} in #{new_resource.domain}")
120
- CF::Preferences.set!(new_resource.key, new_resource.value, new_resource.domain, new_resource.user, new_resource.host)
119
+ CF::Preferences.set!(new_resource.key, new_resource.value, new_resource.domain, to_cf_user(new_resource.user), to_cf_host(new_resource.host))
121
120
  end
122
121
  end
123
122
 
@@ -127,39 +126,35 @@ class Chef
127
126
 
128
127
  converge_by("delete domain:#{new_resource.domain} key:#{new_resource.key}") do
129
128
  Chef::Log.debug("Removing defaults key: #{new_resource.key}")
130
- CF::Preferences.set!(new_resource.key, nil, new_resource.domain, new_resource.user, new_resource.host)
129
+ CF::Preferences.set!(new_resource.key, nil, new_resource.domain, to_cf_user(new_resource.user), to_cf_host(new_resource.host))
131
130
  end
132
131
  end
133
132
 
134
133
  def get_preference(new_resource)
135
- CF::Preferences.get(new_resource.key, new_resource.domain, new_resource.user, new_resource.host)
134
+ CF::Preferences.get(new_resource.key, new_resource.domain, to_cf_user(new_resource.user), to_cf_host(new_resource.host))
136
135
  end
137
136
 
138
- action_class do
139
- require "corefoundation" if RUBY_PLATFORM.match?(/darwin/)
140
-
141
- # Return valid hostname based on the input from host property
142
- def to_cf_host(value)
143
- case value
144
- when :all
145
- CF::Preferences::ALL_HOSTS
146
- when :current
147
- CF::Preferences::CURRENT_HOST
148
- else
149
- value
150
- end
137
+ # Return valid hostname based on the input from host property
138
+ def to_cf_host(value)
139
+ case value
140
+ when :all
141
+ CF::Preferences::ALL_HOSTS
142
+ when :current
143
+ CF::Preferences::CURRENT_HOST
144
+ else
145
+ value
151
146
  end
147
+ end
152
148
 
153
- # Return valid username based on the input from user property
154
- def to_cf_user(value)
155
- case value
156
- when :all
157
- CF::Preferences::ALL_USERS
158
- when :current
159
- CF::Preferences::CURRENT_USER
160
- else
161
- value
162
- end
149
+ # Return valid username based on the input from user property
150
+ def to_cf_user(value)
151
+ case value
152
+ when :all
153
+ CF::Preferences::ALL_USERS
154
+ when :current
155
+ CF::Preferences::CURRENT_USER
156
+ else
157
+ value
163
158
  end
164
159
  end
165
160
  end
@@ -25,10 +25,10 @@ class Chef
25
25
 
26
26
  provides :powershell_package_source
27
27
 
28
- description "Use the **powershell_package_source** resource to register a PowerShell package source and a Powershell package provider. There are 2 distinct objects we care about here. The first is a Package Source like a PowerShell Repository or a Nuget Source. The second object is a provider that PowerShell uses to get to that source with, like PowerShellGet, Nuget, Chocolatey, etc. "
28
+ description "Use the **powershell_package_source** resource to register a PowerShell package source and a Powershell package provider. There are two distinct objects we care about here. The first is a package source like a PowerShell repository or a NuGet Source. The second object is a provider that PowerShell uses to get to that source with, like PowerShellGet, NuGet, Chocolatey, etc."
29
29
  introduced "14.3"
30
30
  examples <<~DOC
31
- **Add a new PSRepository that is not trusted and which requires credentials to connect to**:
31
+ **Add a new PowerShell repository that is not trusted and which requires credentials to connect to**:
32
32
 
33
33
  ```ruby
34
34
  powershell_package_source 'PowerShellModules' do
@@ -43,7 +43,7 @@ class Chef
43
43
  end
44
44
  ```
45
45
 
46
- **Add a new Package Source that uses Chocolatey as the Package Provider**:
46
+ **Add a new package source that uses Chocolatey as the package provider**:
47
47
 
48
48
  ```ruby
49
49
  powershell_package_source 'PowerShellModules' do
@@ -56,7 +56,7 @@ class Chef
56
56
  end
57
57
  ```
58
58
 
59
- **Add a new PowerShell Script source that is trusted**:
59
+ **Add a new PowerShell script source that is trusted**:
60
60
 
61
61
  ```ruby
62
62
  powershell_package_source 'MyDodgyScript' do
@@ -68,7 +68,7 @@ class Chef
68
68
  end
69
69
  ```
70
70
 
71
- **Update my existing PSRepository to make it Trusted after all**:
71
+ **Update an existing PowerShell repository to make it trusted**:
72
72
 
73
73
  ```ruby
74
74
  powershell_package_source 'MyPSModule' do
@@ -137,7 +137,7 @@ class Chef
137
137
  description: "The location where scripts will be published to for this source. Only valid if the provider is `PowerShellGet`."
138
138
 
139
139
  property :trusted, [TrueClass, FalseClass],
140
- description: "Whether or not to trust packages from this source. Used when creating a NON-PSRepository Package Source",
140
+ description: "Whether or not to trust packages from this source. Used when creating a non-PowerShell repository package source.",
141
141
  default: false
142
142
 
143
143
  property :user, String,
@@ -151,7 +151,7 @@ class Chef
151
151
  property :provider_name, String,
152
152
  equal_to: %w{ Programs msi NuGet msu PowerShellGet psl chocolatey winget },
153
153
  validation_message: "The following providers are supported: 'Programs', 'msi', 'NuGet', 'msu', 'PowerShellGet', 'psl', 'chocolatey' or 'winget'",
154
- description: "The package management provider for the package source. The default is PowerShellGet and this option need only be set otherwise in specific use cases.",
154
+ description: "The package management provider for the package source. The default is `PowerShellGet`. Only change this option in specific use cases.",
155
155
  default: "NuGet"
156
156
 
157
157
  load_current_value do
@@ -202,7 +202,7 @@ class Chef
202
202
  end
203
203
  end
204
204
 
205
- action :set, description: "Updates an existing PSRepository or Package Source" do
205
+ action :set, description: "Updates an existing PowerShell repository or package source." do
206
206
  package_details = get_package_source_details
207
207
  output = package_details.result
208
208
  if output == "PSRepository"
@@ -138,7 +138,7 @@ class Chef
138
138
  nil
139
139
  elsif args[0].is_a?(Chef::DelayedEvaluator) && args.count == 1
140
140
  args[0]
141
- elsif args.any? { |a| a.is_a?(Chef::DelayedEvaluator) } && args.count > 1
141
+ elsif args.any?(Chef::DelayedEvaluator) && args.count > 1
142
142
  raise Exceptions::InvalidRemoteFileURI, "Only 1 source argument allowed when using a lazy evaluator"
143
143
  else
144
144
  Array(args).flatten
@@ -79,6 +79,23 @@ class Chef
79
79
  default: false, desired_state: false,
80
80
  introduced: "15.9"
81
81
 
82
+ property :server_url, String,
83
+ description: "The hostname of the subscription service to use. The default is Customer Portal Subscription Management, subscription.rhn.redhat.com. If you do not use this option, the system registers with Customer Portal Subscription Management.",
84
+ introduced: "17.8"
85
+
86
+ property :base_url, String,
87
+ description: "The hostname of the content delivery server to use to receive updates. Both Customer Portal Subscription Management and Subscription Asset Manager use Red Hat's hosted content delivery services, with the URL https://cdn.redhat.com. Since Satellite 6 hosts its own content, the URL must be used for systems registered with Satellite 6.",
88
+ introduced: "17.8"
89
+
90
+ property :service_level, String,
91
+ description: "Sets the service level to use for subscriptions on the registering machine. This is only used with the `auto_attach` option.",
92
+ introduced: "17.8"
93
+
94
+ property :release,
95
+ [Float, String],
96
+ description: "Sets the operating system minor release to use for subscriptions for the system. Products and updates are limited to the specified minor release version. This is used only used with the `auto_attach` option. For example, `release '6.4'` will append `--release=6.4` to the register command.",
97
+ introduced: "17.8"
98
+
82
99
  action :register, description: "Register the node with RHSM." do
83
100
  package "subscription-manager"
84
101
 
@@ -170,6 +187,8 @@ class Chef
170
187
  command << new_resource.activation_key.map { |key| "--activationkey=#{Shellwords.shellescape(key)}" }
171
188
  command << "--org=#{Shellwords.shellescape(new_resource.organization)}"
172
189
  command << "--name=#{Shellwords.shellescape(new_resource.system_name)}" if new_resource.system_name
190
+ command << "--serverurl=#{Shellwords.shellescape(new_resource.server_url)}" if new_resource.server_url
191
+ command << "--baseurl=#{Shellwords.shellescape(new_resource.base_url)}" if new_resource.base_url
173
192
  command << "--force" if new_resource.force
174
193
 
175
194
  return command.join(" ")
@@ -179,11 +198,23 @@ class Chef
179
198
  if new_resource.username && new_resource.password
180
199
  raise "Unable to register - you must specify environment when using username/password" if new_resource.environment.nil? && using_satellite_host?
181
200
 
201
+ if new_resource.service_level
202
+ raise "Unable to register - 'auto_attach' must be enabled when using property `service_level`." unless new_resource.auto_attach
203
+ end
204
+
205
+ if new_resource.release
206
+ raise "Unable to register - `auto_attach` must be enabled when using property `release`." unless new_resource.auto_attach
207
+ end
208
+
182
209
  command << "--username=#{Shellwords.shellescape(new_resource.username)}"
183
210
  command << "--password=#{Shellwords.shellescape(new_resource.password)}"
184
211
  command << "--environment=#{Shellwords.shellescape(new_resource.environment)}" if using_satellite_host?
185
212
  command << "--name=#{Shellwords.shellescape(new_resource.system_name)}" if new_resource.system_name
213
+ command << "--serverurl=#{Shellwords.shellescape(new_resource.server_url)}" if new_resource.server_url
214
+ command << "--baseurl=#{Shellwords.shellescape(new_resource.base_url)}" if new_resource.base_url
186
215
  command << "--auto-attach" if new_resource.auto_attach
216
+ command << "--servicelevel=#{Shellwords.shellescape(new_resource.service_level)}" if new_resource.service_level
217
+ command << "--release=#{Shellwords.shellescape(new_resource.release)}" if new_resource.release
187
218
  command << "--force" if new_resource.force
188
219
 
189
220
  return command.join(" ")
@@ -37,6 +37,13 @@ log_location <%= @log_location %>
37
37
  log_location <%= @log_location.inspect %>
38
38
  <% end -%>
39
39
  <% end -%>
40
+ <%# These data_collector options are special as they have a '.' -%>
41
+ <% unless @data_collector_server_url.nil? || @data_collector_server_url.empty? %>
42
+ data_collector.server_url <%= @data_collector_server_url %>
43
+ <% end %>
44
+ <% unless @data_collector_token.nil? || @data_collector_token.empty? %>
45
+ data_collector.token <%= @data_collector_token %>
46
+ <% end %>
40
47
  <%# The code below is not DRY on purpose to improve readability -%>
41
48
  <% unless @start_handlers.empty? -%>
42
49
  # Do not crash if a start handler is missing / not installed yet
@@ -100,8 +100,8 @@ class Chef
100
100
  install_command << " -Source \"#{new_resource.source}\"" if new_resource.source
101
101
  install_command << " -IncludeManagementTools" if new_resource.management_tools
102
102
 
103
- cmd = powershell_out!(install_command, timeout: new_resource.timeout)
104
- Chef::Log.info(cmd.stdout)
103
+ cmd = powershell_exec!(install_command, timeout: new_resource.timeout)
104
+ Chef::Log.info(cmd.result)
105
105
 
106
106
  reload_cached_powershell_data # Reload cached powershell feature state
107
107
  end
@@ -115,8 +115,8 @@ class Chef
115
115
 
116
116
  unless features_to_remove.empty?
117
117
  converge_by("remove Windows feature#{"s" if features_to_remove.count > 1} #{features_to_remove.join(",")}") do
118
- cmd = powershell_out!("Uninstall-WindowsFeature #{features_to_remove.join(",")}", timeout: new_resource.timeout)
119
- Chef::Log.info(cmd.stdout)
118
+ cmd = powershell_exec!("Uninstall-WindowsFeature #{features_to_remove.join(",")}", timeout: new_resource.timeout)
119
+ Chef::Log.info(cmd.result)
120
120
 
121
121
  reload_cached_powershell_data # Reload cached powershell feature state
122
122
  end
@@ -132,8 +132,8 @@ class Chef
132
132
 
133
133
  unless features_to_delete.empty?
134
134
  converge_by("delete Windows feature#{"s" if features_to_delete.count > 1} #{features_to_delete.join(",")} from the image") do
135
- cmd = powershell_out!("Uninstall-WindowsFeature #{features_to_delete.join(",")} -Remove", timeout: new_resource.timeout)
136
- Chef::Log.info(cmd.stdout)
135
+ cmd = powershell_exec!("Uninstall-WindowsFeature #{features_to_delete.join(",")} -Remove", timeout: new_resource.timeout)
136
+ Chef::Log.info(cmd.result)
137
137
 
138
138
  reload_cached_powershell_data # Reload cached powershell feature state
139
139
  end
@@ -215,9 +215,8 @@ class Chef
215
215
  # fetch the list of available feature names and state in JSON and parse the JSON
216
216
  def parsed_feature_list
217
217
  # Grab raw feature information from WindowsFeature
218
- raw_list_of_features = powershell_out!("Get-WindowsFeature | Select-Object -Property Name,InstallState | ConvertTo-Json -Compress", timeout: new_resource.timeout).stdout
219
-
220
- Chef::JSONCompat.from_json(raw_list_of_features)
218
+ raw_list_of_features = powershell_exec!("Get-WindowsFeature | Select-Object -Property Name,InstallState", timeout: new_resource.timeout).result
219
+ raw_list_of_features || []
221
220
  end
222
221
 
223
222
  # add the features values to the appropriate array
@@ -149,7 +149,6 @@ class Chef
149
149
  DOC
150
150
 
151
151
  allowed_actions :create, :delete, :run, :end, :enable, :disable, :change
152
- default_action :create
153
152
 
154
153
  property :task_name, String, regex: [%r{\A[^/\:\*\?\<\>\|]+\z}],
155
154
  description: "An optional property to set the task name if it differs from the resource block's name. Example: `Task Name` or `/Task Name`",
@@ -182,10 +181,19 @@ class Chef
182
181
  default: false
183
182
 
184
183
  property :frequency_modifier, [Integer, String],
185
- default: 1
184
+ default: 1,
185
+ description: <<~DOCS
186
+ * For frequency `:minute` valid values are 1 to 1439
187
+ * For frequency `:hourly` valid values are 1 to 23
188
+ * For frequency `:daily` valid values are 1 to 365
189
+ * For frequency `:weekly` valid values are 1 to 52
190
+ * For frequency `:monthly` valid values are `('FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST')` OR `1-12`.
191
+ * e.g. If user want to run the task on `second week of the month` use `frequency_modifier` value as `SECOND`. Multiple values for weeks of the month should be comma separated e.g. `"FIRST, THIRD, LAST"`.
192
+ * To run task every (n) months use values 1 to 12.
193
+ DOCS
186
194
 
187
195
  property :frequency, Symbol, equal_to: %i{minute hourly daily weekly monthly once on_logon onstart on_idle none},
188
- description: "The frequency with which to run the task."
196
+ description: "The frequency with which to run the task. Note: This property is required in Chef Infra Client 14.1 or later. Note: The `:once` value requires the `start_time` property to be set."
189
197
 
190
198
  property :start_day, String,
191
199
  description: "Specifies the first date on which the task runs in **MM/DD/YYYY** format.",
@@ -195,7 +203,14 @@ class Chef
195
203
  description: "Specifies the start time to run the task, in **HH:mm** format."
196
204
 
197
205
  property :day, [String, Integer],
198
- description: "The day(s) on which the task runs."
206
+ description: <<~DOCS
207
+ The day(s) on which the task runs.
208
+ * Use this property when setting `frequency` to `:monthly` or `:weekly`.
209
+ * Valid values with frequency `:weekly` are `MON`-`SUN` or `*`.
210
+ * Valid values with frequency `:monthly` are `1-31`, `MON`-`SUN`, and `LASTDAY`.
211
+ * Use `MON`-`SUN` or `LASTDAY` if you are setting `frequency_modifier` as "FIRST, SECOND, THIRD etc." else use 1-31.
212
+ * Multiple days should be comma separated. e.g `1, 2, 3` or `MON, WED, FRI`.
213
+ DOCS
199
214
 
200
215
  property :months, String,
201
216
  description: "The Months of the year on which the task runs, such as: `JAN, FEB` or `*`. Multiple months should be comma delimited. e.g. `Jan, Feb, Mar, Dec`."
@@ -961,7 +976,7 @@ class Chef
961
976
  end
962
977
  end
963
978
 
964
- action :create do
979
+ action :create, description: "Creates a scheduled task, or updates an existing task if any property has changed." do
965
980
  set_command_and_arguments if new_resource.command
966
981
 
967
982
  if current_resource.exists
@@ -998,7 +1013,7 @@ class Chef
998
1013
  end
999
1014
  end
1000
1015
 
1001
- action :run do
1016
+ action :run, description: "Runs a scheduled task." do
1002
1017
  if current_resource.exists
1003
1018
  logger.trace "#{new_resource} task exists"
1004
1019
  if current_resource.task.status == "running"
@@ -1013,7 +1028,7 @@ class Chef
1013
1028
  end
1014
1029
  end
1015
1030
 
1016
- action :delete do
1031
+ action :delete, description: "Deletes a scheduled task." do
1017
1032
  if current_resource.exists
1018
1033
  logger.trace "#{new_resource} task exists"
1019
1034
  converge_by("delete scheduled task #{new_resource}") do
@@ -1026,7 +1041,7 @@ class Chef
1026
1041
  end
1027
1042
  end
1028
1043
 
1029
- action :end do
1044
+ action :end, description: "Ends a scheduled task." do
1030
1045
  if current_resource.exists
1031
1046
  logger.trace "#{new_resource} task exists"
1032
1047
  if current_resource.task.status != "running"
@@ -1041,7 +1056,7 @@ class Chef
1041
1056
  end
1042
1057
  end
1043
1058
 
1044
- action :enable do
1059
+ action :enable, description: "Enables a scheduled task." do
1045
1060
  if current_resource.exists
1046
1061
  logger.trace "#{new_resource} task exists"
1047
1062
  if current_resource.task.status == "not scheduled"
@@ -1058,7 +1073,7 @@ class Chef
1058
1073
  end
1059
1074
  end
1060
1075
 
1061
- action :disable do
1076
+ action :disable, description: "Disables a scheduled task." do
1062
1077
  if current_resource.exists
1063
1078
  logger.info "#{new_resource} task exists"
1064
1079
  if %w{ready running}.include?(current_resource.task.status)