Skip to content

Commit

Permalink
Fix Issue-96 Add AIX Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
TJM committed Feb 28, 2018
1 parent ed7854b commit f0c8120
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 62 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ Compatible with Puppet 4 only. Puppet 4.6.0 will provide best results.
* 8 "Jessie"
* Self Support - should work, support not provided by developer
* Solaris 10, 11
* AIX 7.1, 7.2
* Fedora 24, 25
* SLES 10
* CentOS/RHEL/Scientific/Oracle Linux 5.x
Expand Down
6 changes: 6 additions & 0 deletions data/AIX.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
autofs::service_name: automountd
autofs::package_name: bos.net.nfs.client # NOTE: It seems to be already installed
autofs::auto_master_map: /etc/auto_master
autofs::map_file_group: system
autofs::reload_command: /usr/sbin/automount -v
2 changes: 2 additions & 0 deletions data/Solaris-11.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
autofs::package_name: system/file-system/autofs
5 changes: 5 additions & 0 deletions data/Solaris.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
autofs::package_name: ['SUNWatfsr', 'SUNWatfsu']
autofs::auto_master_map: /etc/auto_master
#autofs::map_file_group: bin # root group exists, but it is bin by default
autofs::reload_command: /usr/sbin/automount -v
13 changes: 13 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
autofs::mounts: {}
autofs::maps: {}
autofs::package_ensure: installed
autofs::package_name: autofs
autofs::package_source: null
autofs::service_ensure: running
autofs::service_enable: true
autofs::service_name: autofs
autofs::auto_master_map: /etc/auto.master
autofs::map_file_owner: root
autofs::map_file_group: root
autofs::reload_command: null
11 changes: 11 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 5
defaults:
data_hash: yaml_data
datadir: data
hierarchy:
- name: "OS Family - Major Version"
path: "%{facts.os.family}-%{facts.os.release.major}.yaml"
- name: "OS Family"
path: "%{facts.os.family}.yaml"
- name: "Common values"
path: "common.yaml"
24 changes: 19 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,31 @@
# @option maps [Boolean] :replace Replace the file if it changes or not.
# @option maps [Integer] :order The order in which to place mapfile contents.
# @param package_ensure Determines the state of the package. Can be set to: installed, absent, lastest, or a specific version string.
# @param package_name Determine the name of the package to install. Should be covered by hieradata.
# @param package_source Determine the source of the package, required on certain platforms (AIX)
# @param service_ensure Determines state of the service. Can be set to: running or stopped.
# @param service_enable Determines if the service should start with the system boot. true
# will start the autofs service on boot. false will not start the autofs service
# on boot.
# @param service_name Determine the name of the service for cross platform compatibility
# @param auto_master_map Filename of the auto.master map for cross platform compatiblity
# @param map_file_owner owner of the automount map files for cross platform compatiblity
# @param map_file_group group of the automount map files for cross platform compatiblity
# @param reload_command In lieu of a service reload capability in Puppet, exec this command to reload automount without restarting it.
#
class autofs (
Hash[String, Hash] $mounts = {},
Hash[String, Hash] $maps = {},
String $package_ensure = 'installed',
Enum[ 'stopped', 'running' ] $service_ensure = 'running',
Boolean $service_enable = true,
Hash[String, Hash] $mounts,
Hash[String, Hash] $maps,
String $package_ensure,
Variant[String, Array[String]] $package_name,
Optional[String] $package_source,
Enum[ 'stopped', 'running' ] $service_ensure,
Boolean $service_enable,
String $service_name,
String $auto_master_map,
String $map_file_owner,
String $map_file_group,
Optional[String] $reload_command,
) {
contain '::autofs::package'
unless $package_ensure == 'absent' {
Expand Down
15 changes: 11 additions & 4 deletions manifests/map.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,22 @@
include '::autofs'

unless $::autofs::package_ensure == 'absent' {
Concat {
notify => Service['autofs'],
if $autofs::reload_command {
Concat {
before => Service[$autofs::service_name],
notify => Exec['automount-reload'],
}
} else {
Concat {
notify => Service[$autofs::service_name],
}
}
}

ensure_resource(concat,$mapfile,{
ensure => $ensure,
owner => 'root',
group => 'root',
owner => $autofs::map_file_owner,
group => $autofs::map_file_group,
mode => $mapmode,
replace => $replace,
require => Class['autofs::package'],
Expand Down
25 changes: 16 additions & 9 deletions manifests/mount.pp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
Integer $order = 1,
Optional[Variant[Stdlib::Absolutepath,Autofs::Mapentry]] $mapfile = undef,
Optional[String] $options = '',
Stdlib::Absolutepath $master = '/etc/auto.master',
Stdlib::Absolutepath $master = $autofs::auto_master_map,
Stdlib::Absolutepath $map_dir = '/etc/auto.master.d',
Boolean $use_dir = false,
Boolean $direct = true,
Expand Down Expand Up @@ -92,15 +92,22 @@
}

unless $::autofs::package_ensure == 'absent' {
Concat {
notify => Service['autofs'],
if $autofs::reload_command {
Concat {
before => Service[$autofs::service_name],
notify => Exec['automount-reload'],
}
} else {
Concat {
notify => Service[$autofs::service_name],
}
}
}

if !defined(Concat[$master]) {
concat { $master:
owner => 'root',
group => 'root',
owner => $autofs::map_file_owner,
group => $autofs::map_file_group,
mode => '0644',
ensure_newline => true,
}
Expand All @@ -125,8 +132,8 @@
} else {
ensure_resource('file', $map_dir, {
'ensure' => directory,
'owner' => 'root',
'group' => 'root',
'owner' => $autofs::map_file_owner,
'group' => $autofs::map_file_group,
'mode' => '0755',
'require' => Class['autofs::package'],
})
Expand All @@ -142,8 +149,8 @@

file { "${map_dir}/${name}.autofs":
ensure => $ensure,
owner => 'root',
group => 'root',
owner => $autofs::map_file_owner,
group => $autofs::map_file_group,
mode => $mapperms,
content => $contents,
require => File[$map_dir],
Expand Down
23 changes: 5 additions & 18 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,11 @@
#
class autofs::package {
assert_private('Package class is private, please use main class parameters')
Package {
ensure => $::autofs::package_ensure,
}
case $facts['os']['family'] {
'Debian', 'Ubuntu': {
package { 'autofs': }
}
'RedHat', 'CentOS': {
package { 'autofs': }
}
'Suse': {
package { 'autofs': }
}
'Solaris': {
# Already installed in Solaris
}
default: {
fail("${facts['operatingsystem']} not supported.")

if $autofs::package_name {
package { $autofs::package_name:
ensure => $::autofs::package_ensure,
source => $autofs::package_source,
}
}
}
11 changes: 10 additions & 1 deletion manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@
#
class autofs::service {
assert_private('Service class is private, please use main class parameters.')
service { 'autofs':
service { $autofs::service_name:
ensure => $autofs::service_ensure,
enable => $autofs::service_enable,
hasstatus => true,
hasrestart => true,
require => Class['autofs::package'],
}

if $autofs::reload_command {
exec { 'automount-reload':
path => '/sbin:/usr/sbin',
command => $autofs::reload_command,
refreshonly => true,
require => Service[$autofs::service_name],
}
}
}
7 changes: 7 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
"10",
"11"
]
},
{
"operatingsystem": "AIX",
"operatingsystemrelease": [
"7.1",
"7.2"
]
}
],
"requirements": [
Expand Down
37 changes: 22 additions & 15 deletions spec/classes/autofs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@

hiera = Hiera.new(config: 'spec/fixtures/hiera/hiera.yaml')

on_supported_os.reject { |_, f| f[:os]['family'] == 'Solaris' }.each do |os, facts|
on_supported_os.each do |os, facts|
case facts[:os]['family']
when 'AIX'
package = 'bos.net.nfs.client'
service = 'automountd'
when 'Solaris'
package = if facts[:os]['release']['major'].to_s == '11'
'system/file-system/autofs'
else
'SUNWatfsu' # and SUNWatfsr, but close enough
end
service = 'autofs'
else
package = 'autofs'
service = 'autofs'
end

context "on #{os}" do
let :facts do
facts
Expand All @@ -23,10 +39,10 @@
it { is_expected.to contain_class('autofs::service') }

# Check Package and service
it { is_expected.to contain_package('autofs').with_ensure('installed') }
it { is_expected.to contain_service('autofs').that_requires('Package[autofs]') }
it { is_expected.to contain_service('autofs').with_ensure('running') }
it { is_expected.to contain_service('autofs').with_enable(true) }
it { is_expected.to contain_package(package).with_ensure('installed') }
it { is_expected.to contain_service(service).that_requires("Package[#{package}]") }
it { is_expected.to contain_service(service).with_ensure('running') }
it { is_expected.to contain_service(service).with_enable(true) }
end
end

Expand All @@ -40,7 +56,7 @@
}
end

it { is_expected.to contain_package('autofs').with_ensure('absent') }
it { is_expected.to contain_package(package).with_ensure('absent') }
end
end

Expand Down Expand Up @@ -117,13 +133,4 @@
is_expected.to compile.and_raise_error(%r{parameter 'mounts' expects a Hash value})
end
end

context 'Solaris Tests' do
mounts = hiera.lookup('autofs::mounts', nil, nil)
let(:facts) { { os: { family: 'Solaris' } } }
let(:params) { { mounts: mounts } }

it { is_expected.not_to contain_package('autofs') }
it { is_expected.not_to contain_service('autofs').that_requires('Package[autofs]') }
end
end
10 changes: 9 additions & 1 deletion spec/defines/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

describe 'autofs::map', type: :define do
on_supported_os.each do |os, facts|
let(:pre_condition) { 'include autofs' }

group = if facts[:os]['family'] == 'AIX'
'system'
else
'root'
end

context "on #{os}" do
let(:title) { 'data' }
let(:facts) do
Expand All @@ -19,7 +27,7 @@
is_expected.to contain_concat('/etc/auto.data').with(
'ensure' => 'present',
'owner' => 'root',
'group' => 'root',
'group' => group,
'mode' => '0644'
)
is_expected.to contain_concat__fragment('/etc/auto.data_data_entries').with(
Expand Down
Loading

0 comments on commit f0c8120

Please sign in to comment.