Skip to content

Commit

Permalink
Major fixes for ensure=> absent
Browse files Browse the repository at this point in the history
  • Loading branch information
keeleysam committed Oct 28, 2016
1 parent 2433c50 commit 4c00e0a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 49 deletions.
11 changes: 0 additions & 11 deletions Modulefile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# mac_profiles_handler module for Puppet

## Description
This module provides two resource types for interacting with OS X configuration profiles.
This module provides two resource types for interacting with macOS configuration profiles.

The profile_manager resource type is the back-end type that interacts with /usr/bin/profiles for creating, destroying and verifying a resource type. The mac_profiles_handler::manage resource type is user-facing and handles the management of the actual files.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'puppet/util/plist'

Puppet::Type.type(:profile_manager).provide :osx do
desc 'Provides management of mobileconfig profiles on OS X.'
Puppet::Type.type(:profile_manager).provide :macos do
desc 'Provides management of mobileconfig profiles on macOS.'

confine operatingsystem: :darwin

Expand All @@ -19,14 +19,15 @@ def destroy
end

def exists?
installed
end

def installed
# if already installed, check if it is the right one.
# if not installed, return false.
# if we are removing, don't care if it is the right one.
if Facter.value(:profiles).include? resource[:name]
return current
if resource[:ensure] == :absent
return true
else
return current
end
else
return false
end
Expand Down
67 changes: 37 additions & 30 deletions manifests/manage.pp
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
# manage mac profiles
define mac_profiles_handler::manage(
$file_source,
$ensure,
$file_source = '',
$ensure = 'present',
$type = 'mobileconfig',
) {

if $facts['os']['name'] != 'Darwin' {
fail('The mobileconfig::manage resource type is only supported on OS X')
fail('The mobileconfig::manage resource type is only supported on macOS')
}

File {
owner => 'root',
group => 'wheel',
mode => '0700',
}

if ! defined(File["${facts['puppet_vardir']}/mobileconfigs"]) {
file { "${facts['puppet_vardir']}/mobileconfigs":
ensure => directory,
}
}
case $type {
'template': {
file { "${facts['puppet_vardir']}/mobileconfigs/${name}":
ensure => file,
content => $file_source,
case $ensure {
'absent': {
profile_manager { $name:
ensure => $ensure,
}
}
default: {
file { "${facts['puppet_vardir']}/mobileconfigs/${name}":
ensure => file,
source => $file_source,
File {
owner => 'root',
group => 'wheel',
mode => '0700',
}
}
}

profile_manager { $name:
ensure => $ensure,
profile => "${facts['puppet_vardir']}/mobileconfigs/${name}",
require => File["${facts['puppet_vardir']}/mobileconfigs/${name}"],
subscribe => File["${facts['puppet_vardir']}/mobileconfigs/${name}"],
if ! defined(File["${facts['puppet_vardir']}/mobileconfigs"]) {
file { "${facts['puppet_vardir']}/mobileconfigs":
ensure => directory,
}
}
case $type {
'template': {
file { "${facts['puppet_vardir']}/mobileconfigs/${name}":
ensure => file,
content => $file_source,
}
}
default: {
file { "${facts['puppet_vardir']}/mobileconfigs/${name}":
ensure => file,
source => $file_source,
}
}
}
profile_manager { $name:
ensure => $ensure,
profile => "${facts['puppet_vardir']}/mobileconfigs/${name}",
require => File["${facts['puppet_vardir']}/mobileconfigs/${name}"],
subscribe => File["${facts['puppet_vardir']}/mobileconfigs/${name}"],
}
}
}


}

33 changes: 33 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "puppet-mac_profiles_handler",
"author": "",
"license": "",
"version": "2.0.0",
"summary": "Puppet Module for managing macOS Configuration Profiles",
"source": "https://github.com/keeleysam/puppet-mac_profiles_handler",
"project_page": "https://github.com/keeleysam/puppet-mac_profiles_handler",
"issues_url": "https://github.com/keeleysam/puppet-mac_profiles_handler/issues",
"tags": [
"macOS",
"OS X",
"mobileconfig",
"profiles"
],
"operatingsystem_support": [
{
"operatingsystem": "Darwin"
}
],
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 4.4.0"
}
],
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 2.3.1"
}
]
}

0 comments on commit 4c00e0a

Please sign in to comment.