Chef Infra Client: 15.x
How is the following possible? Well, in order to speed up operations, Chef Infra Client keeps a cache of package repositories and their contents. If a new, previously unknown package repository has been added during the same run, Chef Infra Client will be unaware of the change without action on the recipe creator's part. Read on for a possible solution.
$ sudo yum info splunkforwarder
Updating Subscription Management repositories.
Last metadata expiration check: 0:14:49 ago on Fri 17 Apr 2020 10:14:17 AM EDT.
Name : splunkforwarder
Version : 7.2.6
Release : c0bf0f679ce9
Architecture : x86_64
Size : 24 M
Source : splunkforwarder-7.2.6-c0bf0f679ce9.src.rpm
Repository : r701
Summary : SplunkForwarder
License : Commercial
Description : The platform for machine data.
$ sudo chef-client
* No candidate version available for splunkforwarder
Error executing action `install` on resource 'dnf_package[splunkforwarder]'
No candidate version available for splunkforwarder
The above output is from RHEL8, but if we use the generic package resource, the system will figure out what's needed, be it yum, dnf, whatever. The important part is the flush_cache [ :before ] below. This causes the package provider to refresh the cache of package information to match any newly installed respositories, and only then does it attempt the package install. This is required because of the cache. Chef Infra Client's package resource only refreshes the cache once, on startup, then it works off of that cache throughout the lifetime of the run.
package 'splunkforwarder' do
flush_cache [ :before ]