puppet-archive
puppet-archive copied to clipboard
Use same archive multiple times (change namevar)
Affected Puppet, Ruby, OS and module versions/distributions
- Puppet: 7.0.0
- Ruby: 2.5.0
- Distribution: openSuse 15.2
- Module version: 4.6.0 (latest from forge.puppet.com)
How to reproduce (e.g Puppet code you use)
Define the Archive resource 2 or more times where only the extract_path
attribute is different. Then run puppet agent
What are you seeing
command: puppet agent --verbose --noop --onetime --no-daemonize --server server.puppet.domain
fails
What behaviour did you expect instead
That the same archive will be untarred to 2 different locations.
Output log
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Resource Statement, Cannot alias Archive[archive.tar.xz] to ["/local/save/path/of/archive.tar.xz"] at (file: init.pp, line: 10); resource ["Archive", "/local/save/path/of/archive.tar.xz"] already declared (file: init.pp, line: 20) (file: init.pp, line: 10, on node client.puppet.domain
Any additional information you'd like to impart
The namevar
is bound to the path
attribute, while, I think, binding it to the extract_path
should be better (or a combination of path
and extract_path
, as this is the real unique combination).
I did a quick check by changing the namevar in lib/puppet/type/archive.rb
, but when i run puppet agent
I get this message: Error: Failed to apply catalog: undefined method `value' for nil:NilClass
As a workaround, you can set the name of the resource to something unique, and specify the path
and other attributes.
Unless I miss something, which is perfectly possible, that does not help (already have that). From my understanding, correct me if I'm wrong, in the ruby file lib/puppet/type/archive.rb
(line 53; which defines the resource) has marked the path
property as namevar
. So internally it looks at the value of that property, and as I would like to keep that property the same (re-use archive), it fails.
That just allows you to specify the path
as the name of the resource. You can still set the name of the resource to whatever you want, if you separately provide the path
attribute.
/tmp/test.pp
:
archive { 'something unique here':
ensure => present,
path => '/tmp/vagrant.deb',
source => 'https://releases.hashicorp.com/vagrant/2.2.3/vagrant_2.2.3_x86_64.deb',
}
From the output of puppet apply --test /tmp/test.pp
:
Notice: /Stage[main]/Main/Archive[something unique here]/ensure: download archive from https://releases.hashicorp.com/vagrant/2.2.3/vagrant_2.2.3_x86_64.deb to /tmp/vagrant.deb with cleanup
I seem to be hitting the same behaviour too, I have an archive that already exists on the system and I'd like to extract it's contents multiple times however no combination of parameters seems to work for me.
Let's say I have a archive that exists at '/opt/testing/test.tar.gz' if I try to extract it to two differing locations with the following:
archive { "extract_test_1":
path => '/opt/testing/test.tar.gz',
extract => true,
extract_path => '/opt/test/test1',
creates => '/opt/test/test1/config.xml',
user => 'test_acc'
}
archive { "extract_test_2":
path => '/opt/testing/test.tar.gz',
extract => true,
extract_path => '/opt/test/test2',
creates => '/opt/test/test2/config.xml',
user => 'test_acc'
}
I get the following error:
Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Resource Statement, Cannot alias Archive[extract_test_2] to ["/opt/testing/test.tar.gz"] at (file: /tmp/kitchen/modules/test/manifests/runner.pp, line: 31); resource ["Archive", "/opt/testing/test.tar.gz"] already declared (file: /tmp/kitchen/modules/test/manifests/runner.pp, line: 31) (file: /tmp/kitchen/modules/test/manifests/runner.pp, line: 31, column: 3) (file: /tmp/kitchen/modules/test/manifests/init.pp, line: 51) on node linux-tests-ubuntu-2004.vagrantup.com