I've created two ruby facts ecdsa.rb
and ed25519.rb
and it checks if file exists. If it does exists then add a line to a file. But it adds both lines even though the second file doesn't exists.
Facter shows that the second file doesn't exists.
root@hostname:~# facter --json -p ecdsa_key_exists
{
"ecdsa_key_exists": true
}
root@hostname:~# facter --json -p ed25519_key_exists
{
"ed25519_key_exists": false
}
Here is the custom fact I wrote.
ecdsa.rb content:
File /etc/ssh/ssh_host_ecdsa_key Exists.
Facter.add('ecdsa_key_exists') do
setcode do
File.exists?('/etc/ssh/ssh_host_ecdsa_key')
end
end
ed25519.rb content:
File /etc/ssh/ssh_host_ed25519_key has been deleted from the test server.
Facter.add('ed25519_key_exists') do
setcode do
File.exists?('/etc/ssh/ssh_host_ed25519_key')
end
end
Template test.erb:
<% if @ecdsa_key_exists -%>HostKey /etc/ssh/ssh_host_ecdsa_key<% end %>
<% if @ed25519_key_exists -%>HostKey /etc/ssh/ssh_host_ed25519_key<% end %>
But when I run puppet agent -t, both lines gets added even though @ed25519_key_exists returns false.
puppet module init.pp:
file { 'test.conf':
path => '/tmp/test.conf',
ensure => file,
content => template("ssh/test.erb"),
}