-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently it is not possible to have a template file.epp ```puppet <%- | Stdlib::Port $port, String[1] $password, | %> port <%= $port %> password <%= $password %> ``` and run ```puppet file{'/tmp/junk': content => stdlib::deferrable_epp('module/file.epp', { 'port' => '1234', pass => Deferred('secrets::get',['mysecret'])}), } ``` since the deferred template substitution will fail: ``` Error: Failed to apply catalog: Evaluation Error: Resource type not found: Stdlib::Port (file: inlined-epp-text, line: 2, column: 3) ``` due to Stdlib::Port not being available on the agent node. This change now parses the EPP twice. The first pass will reduce the template to: ```puppet port = 1234 password <%= $password %> ``` and this simpler template will be passed in deferred mode. Note the original template type for password must accept the intermediate generated value of `<%= $password %>` which is typically case for a secret password.
- Loading branch information
1 parent
d871c4d
commit 60fd443
Showing
4 changed files
with
188 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper_acceptance' | ||
|
||
describe 'stdlib::deferable_epp function' do | ||
let(:testfile) { (os[:family] == 'windows') ? 'C:\\test.epp' : '/tmp/test.epp' } | ||
|
||
before(:all) do | ||
apply_manifest(<<-MANIFEST) | ||
$_epp = @(EPP) | ||
<%- | | ||
Stdlib::Port $port, | ||
String[1] $password, | ||
| -%> | ||
port=<%= $port %> | ||
password=<%= $password %>" | ||
| EPP | ||
$_testfile = $facts['os']['family'] ? { | ||
'windows' => 'C:\\test.epp', | ||
default => '/tmp/test.epp', | ||
} | ||
file{ $_testfile: | ||
ensure => file, | ||
content => $_epp, | ||
} | ||
MANIFEST | ||
end | ||
|
||
before(:each) do | ||
rm_testfile = <<-MANIFEST | ||
$_testfile = $facts['os']['family'] ? { | ||
'windows' => 'C:\\test.epp', | ||
default => '/tmp/test.epp', | ||
} | ||
file { "${_testfile}.rendered": | ||
ensure => absent, | ||
} | ||
MANIFEST | ||
apply_manifest(rm_testfile) | ||
end | ||
|
||
context 'with no deferred values' do | ||
let(:pp) do | ||
<<-MANIFEST | ||
$_testfile = $facts['os']['family'] ? { | ||
'windows' => 'C:\\test.epp', | ||
default => '/tmp/test.epp', | ||
} | ||
file{ "${_testfile}.rendered": | ||
ensure => file, | ||
content => stdlib::deferrable_epp( | ||
$_testfile, | ||
{'port' => 1234, 'password' => 'top_secret'} | ||
), | ||
} | ||
MANIFEST | ||
end | ||
|
||
it 'applies manifest, generates file' do | ||
idempotent_apply(pp) | ||
expect(file("#{testfile}.rendered")).to be_file | ||
expect(file("#{testfile}.rendered").content).to match(%r{port=1234}) | ||
expect(file("#{testfile}.rendered").content).to match(%r{password=top_secret}) | ||
end | ||
end | ||
|
||
context 'with deferred values' do | ||
let(:pp) do | ||
<<-MANIFEST | ||
$_testfile = $facts['os']['family'] ? { | ||
'windows' => 'C:\\test.epp', | ||
default => '/tmp/test.epp', | ||
} | ||
file{ "${_testfile}.rendered": | ||
ensure => file, | ||
content => stdlib::deferrable_epp( | ||
$_testfile, | ||
{'port' => 1234, 'password' => Deferred('inline_epp',['<%= $secret_password %>',{'secret_password' => 'so_secret'}])}, | ||
), | ||
} | ||
MANIFEST | ||
end | ||
|
||
it 'applies manifest, generates file' do | ||
idempotent_apply(pp) | ||
expect(file("#{testfile}.rendered")).to be_file | ||
expect(file("#{testfile}.rendered").content).to match(%r{port=1234}) | ||
expect(file("#{testfile}.rendered").content).to match(%r{password=so_secret}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters