Skip to content

Commit

Permalink
Add support for setting tmpdir for local transport
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Oct 31, 2024
1 parent c955031 commit d62879f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ The following parameters are available in the `bolt::project` defined type:
* [`manage_user`](#-bolt--project--manage_user)
* [`environment`](#-bolt--project--environment)
* [`modulepaths`](#-bolt--project--modulepaths)
* [`local_transport_tmpdir`](#-bolt--project--local_transport_tmpdir)

##### <a name="-bolt--project--basepath"></a>`basepath`

Expand Down Expand Up @@ -206,3 +207,11 @@ an array of directories where code lives

Default value: `["/etc/puppetlabs/code/environments/${environment}/modules", "/etc/puppetlabs/code/environments/${environment}/site", '/opt/puppetlabs/puppet/modules']`

##### <a name="-bolt--project--local_transport_tmpdir"></a>`local_transport_tmpdir`

Data type: `Optional[Stdlib::Absolutepath]`

the bolt tmpdir for all local transports

Default value: `undef`

11 changes: 9 additions & 2 deletions manifests/project.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# @param manage_user if we should create the user+group or not
# @param environment the desired code environment we will use
# @param modulepaths an array of directories where code lives
# @param local_transport_tmpdir the bolt tmpdir for all local transports
#
# @example create one project and provide plan parameters
# bolt::project { 'peadmmig': }
Expand All @@ -27,6 +28,7 @@
Boolean $manage_user = true,
String[1] $environment = 'peadm',
Array[Stdlib::Absolutepath] $modulepaths = ["/etc/puppetlabs/code/environments/${environment}/modules", "/etc/puppetlabs/code/environments/${environment}/site", '/opt/puppetlabs/puppet/modules'],
Optional[Stdlib::Absolutepath] $local_transport_tmpdir = undef,
) {
unless $facts['pe_status_check_role'] {
fail('pe_status_check_role fact is missing from module puppetlabs/pe_status_check')
Expand Down Expand Up @@ -78,6 +80,11 @@
content => $bolt_project,
}

$inventory_config = if $local_transport_tmpdir {
{ 'config' => { 'local' => { 'tmpdir' => $local_transport_tmpdir } } }
} else {
{}
}
$inventory = {
'groups' => [
{
Expand All @@ -90,13 +97,13 @@
]
}
],
}.stdlib::to_yaml({ indentation => 2 })
} + $inventory_config

file { "${project_path}/inventory.yaml":
ensure => 'file',
owner => $owner,
group => $group,
content => $inventory,
content => $inventory.stdlib::to_yaml({ indentation => 2 }),
}

$data = { 'project' => $project, 'user'=> $owner, 'group' => $group, 'project_path' => $project_path, 'environment' => 'peadm' }
Expand Down
47 changes: 26 additions & 21 deletions spec/defines/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@

on_supported_os.each do |os, os_facts|
context "on #{os}" do
context 'with defaults' do
context 'on FOSS' do
let :facts do
os_facts
end

it { is_expected.to compile.and_raise_error(%r{pe_status_check_role fact is missing from module puppetlabs/pe_status_check}) }
context 'on FOSS' do
let :facts do
os_facts
end

context 'on PE' do
let :facts do
os_facts.merge({ pe_status_check_role: 'primary', sudoversion: '1.9.5p2' })
end
it { is_expected.to compile.and_raise_error(%r{pe_status_check_role fact is missing from module puppetlabs/pe_status_check}) }
end

context 'on PE' do
let :facts do
os_facts.merge({ pe_status_check_role: 'primary', sudoversion: '1.9.5p2' })
end

context 'with defaults' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('bolt') }
it { is_expected.to contain_file('/opt/peadm/bolt-project.yaml').with_ensure('file') }
it { is_expected.to contain_file('/opt/peadm/inventory.yaml').with_ensure('file') }
it { is_expected.to contain_file('/opt/peadm/inventory.yaml').with_ensure('file').without_content(%r{tmpdir}) }
it { is_expected.to contain_file('/opt/peadm').with_ensure('directory') }
it { is_expected.to contain_user(title) }
it { is_expected.to contain_group(title) }
Expand All @@ -41,18 +41,23 @@
it { is_expected.to contain_apt__source('puppet-tools-release') }
end
end
end

context 'with manage_user=false on PE' do
let :facts do
os_facts.merge({ pe_status_check_role: 'primary', sudoversion: '1.9.5p2' })
end
let :params do
{ manage_user: false }
context 'with manage_user=false on PE' do
let :params do
{ manage_user: false }
end

it { is_expected.not_to contain_user(title) }
it { is_expected.not_to contain_group(title) }
end

it { is_expected.not_to contain_user(title) }
it { is_expected.not_to contain_group(title) }
context 'with local_transport_tmpdir' do
let :params do
{ local_transport_tmpdir: '/foooo' }
end

it { is_expected.to contain_file('/opt/peadm/inventory.yaml').with_ensure('file').with_content(%r{tmpdir: "/foooo"}) }
end
end
end
end
Expand Down

0 comments on commit d62879f

Please sign in to comment.