Chef Yum Mac OS

broken image


  1. Chef Yum Mac Os 11
  2. Mac Os Mojave
  3. Chef Yum Mac Os X

Background

In Chef 12 the old Chef::Platform hashmap located in `lib/chef/platform/provider_mapping.rb` has been deprecated. In its place is a dynamic provider and resolver resolution mechanism which is preferred and which can be manipulated via DSL methods on the resource and provider. In Chef 11 it was common to add functionality for platforms in the Chef::Platform hashmap which looks like this:

[ruby]
class Chef
class Platform

But UNIX operating system doesn't come under the broad category of an open-source operating system for which developers can edit it. Free of Cost: One of the biggest reason that it is broadly used is Linux operating system is free of cost. Linux operating system is free, but UNIX Operating system is not free. We can download it from the internet.

  • YUMI for Mac OS makes use of syslinux also extracted distributions saved on the USB system and reverted to utilizing grub to Boot Some ISO records data from USB, if essential. If the setup portion of any Dwell Linux distro does work, take into account it a bonus.
  • Did some debugging on Mac OS X Mavericks and the install.sh 'Omnibus installer' creates a temp directory containing chef-macosx-10.7-x8664.sh (10.7 atm) that creates another temp directory containing makeselfinst that has DESTDIR=/opt/chef in it. So that's true, deleting /opt/chef removes it but there will be some symlinks in /usr/bin pointing to nowhere you might also want to remove.

class << self
attr_writer :platforms

Chef Yum Mac Os 11

def platforms
@platforms ||= begin
require ‘chef/providers'

{
:mac_os_x => {
:default => {
:package => Chef::Provider::Package::Macports,
:service => Chef::Provider::Service::Macosx,
:user => Chef::Provider::User::Dscl,
:group => Chef::Provider::Group::Dscl
}
},
:mac_os_x_server => {
:default => {
:package => Chef::Provider::Package::Macports,
:service => Chef::Provider::Service::Macosx,
:user => Chef::Provider::User::Dscl,
:group => Chef::Provider::Group::Dscl
}
},
:freebsd => {
:default => {
:group => Chef::Provider::Group::Pw,
:service => Chef::Provider::Service::Freebsd,
:user => Chef::Provider::User::Pw,
:cron => Chef::Provider::Cron
}
},
[…etc for 400 lines…]
}
end
end
[…etc…]
[/ruby]

Examples of New Syntax

With chef-12 we are starting to wire up providers and resolvers via the `provides` method on the provider and resource classes. Some examples of this include:

Wiring up a resource on all platforms

This is the most trivial example where all platforms get the same cookbook_file resource when the user types ‘cookbook_file' in a recipe:

[ruby]
class Chef
class Resource
class CookbookFile < Chef::Resource::File
provides :cookbook_file
[…etc…]
end
end
end
[/ruby]

Wiring up a resource on an os

This only wires up the ips_package resource when the node[‘os'] attribute is ‘solaris2'

[ruby]
class Chef
class Resource
class IpsPackage < ::Chef::Resource::Package

provides :ips_package, os: 'solaris2'
end
end
end
[/ruby]

Wiring up a resource on multiple platform_families

This is a more complicated example, showing that the provides line supports node[‘platform_family'] and that arrays of values can be used. This also wires up the the yum_package resource to whenever the user types ‘yum_package' in a recipe no matter which platform (so even on Solaris if you type ‘yum_package' in a recipe you'll get this kind of resource), but also on the redhat-like platform_families if the user types ‘package' we wire that up to resolve to the ‘yum_package' resource. This is a slight change from Chef 11 where if you typed ‘package 'foo'‘ on redhat you would get a vanilla Chef::Resource::Package object which would do vanilla package validation checking and any yum-specific options would be rejected. In Chef 12 on redhat you will get a Chef::Resource::YumPackage object which will do the correct validation for the YumPackage provider.

[ruby]
class Chef
class Resource
class YumPackage < Chef::Resource::Package

provides :yum_package
provides :package, os: 'linux', platform_family: [ 'rhel', 'fedora' ]
end
end
end
[/ruby]

Wiring up a Resource based on arbitrary node attributes

On Solaris2 for platform_version of <= 5.10 we need to use solaris_package while on platform_version of >= 5.11 we need to use ips_package so our provides line looks like this:

[ruby]
class Chef
class Resource
class SolarisPackage < Chef::Resource::Package

provides :solaris_package
provides :package, os: 'solaris2', platform_family: 'nexentacore'
provides :package, os: 'solaris2', platform_family: 'solaris2' do |node|
# on >= Solaris 11 we default to IPS packages instead
node[:platform_version].to_f <= 5.10
end

end
end
end
[/ruby]

Resource and Provider Provides Lines

For every provides line in a Resource file there should generally be a corresponding provides line in the Provider file. Resources should no longer set the provider explicitly in the constructor of the Resource. It still works to explicitly define the provider in the Resource but this will bypass dynamic provider resolution. It also still works to not have a provides line in the provider file and mangling based on the resource name will still be able to determine the provider, but this is deprecated and soon Chef will warn and then eventually fail if you don't have matching provides lines in both the Resource and Provider.

Supported Provides Syntax

The provides line has ‘os', ‘platform' and ‘platform_family' options which match either arrays or strings. It will also take a block that the node object is passed to and which is expect to return true if the wiring should be done on the node. When multiple matchers are present all of the conditionals must be true. Multiple provides lines can be used for multiple conditions, and the array syntax also matches any of the array components.

[ruby]
provides :cookbook_file
provides :package, os: 'windows'
provides :rpm_package, os: [ 'linux', 'aix' ]
provides :package, os: 'solaris2', platform_family: 'smartos'
provides :package, platform: 'freebsd'
provides :package, os: 'linux', platform_family: [ 'rhel', 'fedora' ]
provides :package, os: 'solaris2', platform_family: 'solaris2' do |node|
node[:platform_version].to_f <= 5.10
end
[/ruby]

The implementation of the syntax is contained within the lib/chef/node_map.rb file. A Chef::NodeMap object is a key-value store where the values can be inserted with conditions based on the node object (and then only if the node object matches will they be retrieved).

Dynamic Provider Resolution

Providers also do dynamic resolution. They also have additional methods that they can override to implement Chef::Provider.provides? and Chef::Provider.supports? methods to determine if the platform supports a given provider (e.g. 'is systemd the init system or not?') and if the provider provides? a given resource (e.g. 'is service ‘foo' managed by sysv init scripts or upstart?'). This is almost entirely designed to dynamically handle the use case of Linux init script systems, and the details are out of the scope of this blog post for today. Adventuresome users can poke around the service providers.

LWRP usage

This can be used to wire up LWRPs to arbitrary names! You are no longer bound by the ‘[cookbook_name]_[provider_filename]' default and can even wire up your own LWRPs to the package provider if you want to (although there be dragons — consider that if we ever implement the package provider on your platform in core chef that your custom package provider will collide with the new core chef one and you may break in a minor release since this is an API extension for us, and not a breaking change for our API).

A simple example:

Chef yum mac os 11

resources/default.rb:

[ruby]
actions :run
default_action :run

provides :foo_bar

attribute :thing, kind_of: String, name_attribute: true
[/ruby]

providers/default.rb:

[ruby]
use_inline_resources

provides :foo_bar

action :run do
Chef::Log.warn new_resource.thing
end
[/ruby]

recipes/default.rb:

[ruby]
foo_bar 'baz'
[/ruby]

LWRP Chef-11 BackCompat

It turns out that Chef-11 supports the ‘provides' syntax on resources, so that this feature can be used in community cookbooks and other places where Chef-11 backcompat is still important. Chef-12 simply improved on the API which was already present for Resources. It does not allow the ‘provides' syntax on Providers, and it only takes an 'on_platform:' argument (Chef-12 also supports 'on_platform' as an alias for 'platform' for back-compat). To rename LWRPs and maintain Chef-11 backcompat simply drop the ‘provides' line from the Provider, or ideally protect it with an ‘if respond_to?(:provides)' check.

Status

The dynamic Provider and Resolver features are still under development and were not completed with Chef 12. There are still entries in the Chef::Platform platform_map which need to be converted into dynamic resolution and emptied out. Eventually that hash table needs to be completely dropped. There is magic name-to-class mangling that occurs in both Resources and Providers that will be dropped. There are useful helper modules for determining the init system the host is using which need to be exposed as DSL helper methods to assist in writing cookbook code that needs to switch behavior based on the init system actually being used.

There are also currently no docs at docs.chef.io for any of these APIs (if your name is James Scott you should ping me about fixing this).

Use the macports_package resource to manage packages for the Mac OS X platform.

Note

In many cases, it is better to use the package resource instead of this one. This is because when the package resource is used in a recipe, the chef-client will use details that are collected by Ohai at the start of the chef-client run to determine the correct package application. Using the package resource allows a recipe to be authored in a way that allows it to be used across many platforms.

Syntax¶

A macports_package resource block manages a package on a node, typically by installing it. The simplest use of the macports_package resource is:

which will install the named package using all of the default options and the default action (:install).

The full syntax for all of the properties that are available to the macports_package resource is:

where

  • macports_package tells the chef-client to manage a package
  • 'name' is the name of the package
  • :action identifies which steps the chef-client will take to bring the node into the desired state
  • options, package_name, provider, source, timeout, and version are properties of this resource, with the Ruby type shown. See 'Properties' section below for more information about all of the properties that may be used with this resource.

Actions¶

This resource has the following actions:

:install
Default. Install a package. If a version is specified, install the specified version of the package.
:nothing
Define this resource block to do nothing until notified by another resource to take action. When this resource is notified, this resource block is either run immediately or it is queued up to be run at the end of the chef-client run.
:purge
Purge a package. This action typically removes the configuration files as well as the package.
:remove
Remove a package.
:upgrade
Install a package and/or ensure that a package is the latest version.

Properties¶

This resource has the following properties:

ignore_failure

Ruby Types: TrueClass, FalseClass

Continue running a recipe if a resource fails for any reason. Default value: false.

notifies

Ruby Type: Symbol, ‘Chef::Resource[String]'

A resource may notify another resource to take action when its state changes. Specify a 'resource[name]', the :action that resource should take, and then the :timer for that action. A resource may notifiy more than one resource; use a notifies statement for each resource to be notified.

A timer specifies the point during the chef-client run at which a notification is run. The following timers are available:

:before
Specifies that the action on a notified resource should be run before processing the resource block in which the notification is located.
:delayed
Default. Specifies that a notification should be queued up, and then executed at the very end of the chef-client run.
:immediate, :immediately
Specifies that a notification should be run immediately, per resource notified.

The syntax for notifies is:

options

Ruby Type: String

One (or more) additional options that are passed to the command.

package_name

Ruby Types: String, Array

The name of the package. Default value: the name of the resource block See 'Syntax' section above for more information.

provider

Ruby Type: Chef Class

Optional. Explicitly specifies a provider. See 'Providers' section below for more information.

retries

Ruby Type: Integer

The number of times to catch exceptions and retry the resource. Default value: 0.

retry_delay

Ruby Type: Integer

The retry delay (in seconds). Default value: 2.

source

Ruby Type: String

Optional. The path to a package in the local file system.

subscribes

Ruby Type: Symbol, ‘Chef::Resource[String]'

A resource may listen to another resource, and then take action if the state of the resource being listened to changes. Specify a 'resource[name]', the :action to be taken, and then the :timer for that action.

A timer specifies the point during the chef-client run at which a notification is run. The following timers are available:

:before
Specifies that the action on a notified resource should be run before processing the resource block in which the notification is located.
:delayed
Default. Specifies that a notification should be queued up, and then executed at the very end of the chef-client run.
:immediate, :immediately
Specifies that a notification should be run immediately, per resource notified.

Yellow roses mac os. The syntax for subscribes is:

timeout

Ruby Types: String, Integer

The amount of time (in seconds) to wait before timing out.

version

Ruby Types: String, Array

The version of a package to be installed or upgraded.

Mac Os Mojave

Providers¶

Where a resource represents a piece of the system (and its desired state), a provider defines the steps that are needed to bring that piece of the system from its current state into the desired state.

The chef-client will determine the correct provider based on configuration data collected by Ohai at the start of the chef-client run. This configuration data is then mapped to a platform and an associated list of providers.

Generally, it's best to let the chef-client choose the provider, and this is (by far) the most common approach. However, in some cases, specifying a provider may be desirable. There are two approaches:

  • Use a more specific short name—yum_package'foo'do instead of package'foo'do, script'foo'do instead of bash'foo'do, and so on—when available
  • Use the provider property within the resource block to specify the long name of the provider as a property of a resource. For example: providerChef::Provider::Long::Name

This resource has the following providers:

Chef::Provider::Package, package
When this short name is used, the chef-client will attempt to determine the correct provider during the chef-client run.
Chef::Provider::Package::Macports, macports_package
The provider for the Mac OS X platform.

Examples¶

The following examples demonstrate various approaches for using resources in recipes. If you want to see examples of how Chef uses resources in recipes, take a closer look at the cookbooks that Chef authors and maintains: https://github.com/chef-cookbooks.

Chef Yum Mac Os X

Install a package





broken image