From d62879faf55e7bcd3840a5696b36b9e7289179d5 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Thu, 31 Oct 2024 14:18:32 +0100 Subject: [PATCH] Add support for setting tmpdir for local transport --- REFERENCE.md | 9 +++++++ manifests/project.pp | 11 +++++++-- spec/defines/project_spec.rb | 47 ++++++++++++++++++++---------------- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 681eea7..d87202c 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -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) ##### `basepath` @@ -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']` +##### `local_transport_tmpdir` + +Data type: `Optional[Stdlib::Absolutepath]` + +the bolt tmpdir for all local transports + +Default value: `undef` + diff --git a/manifests/project.pp b/manifests/project.pp index 1bb28b6..0bb3657 100644 --- a/manifests/project.pp +++ b/manifests/project.pp @@ -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': } @@ -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') @@ -78,6 +80,11 @@ content => $bolt_project, } + $inventory_config = if $local_transport_tmpdir { + { 'config' => { 'local' => { 'tmpdir' => $local_transport_tmpdir } } } + } else { + {} + } $inventory = { 'groups' => [ { @@ -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' } diff --git a/spec/defines/project_spec.rb b/spec/defines/project_spec.rb index 24525de..fe83994 100644 --- a/spec/defines/project_spec.rb +++ b/spec/defines/project_spec.rb @@ -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) } @@ -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