Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only grep for last 8 characters as this is what apt-key list returns #373

Closed
wants to merge 1 commit into from

Conversation

szponek
Copy link

@szponek szponek commented Dec 5, 2017

This fixes #367 by grepping only the last 8 characters of the key ID, which is what apt-key list returns on Debian and Ubuntu

@truthbk
Copy link
Member

truthbk commented Dec 5, 2017

@szponek thanks for this - I'll try to fix the tests for older puppets DSL, got to check how we can grab the substring there. This is ready to go as soon as we get that sorted.

Copy link
Member

@truthbk truthbk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szponek almost ready - as you can see from the tests, this breaks for older puppets, I believe using a hash '#' instead of a '$' should fix the substring.

@@ -15,6 +15,6 @@
define datadog_agent::ubuntu::install_key() {
exec { "key ${name}":
command => "/usr/bin/apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys ${name}",
unless => "/usr/bin/apt-key list | grep ${name} | grep expires",
unless => "/usr/bin/apt-key list | grep ${name[-8,8]} | grep expires",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be:

unless  => "/usr/bin/apt-key list | grep #{name[-8,8]} | grep expires",

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@truthbk are you sure #{var} is a valid way for variable interpolation? It doesn't work on puppet 5.3.2 for me:

[szponek@szponek tmp]$ cat test1.pp 

$test='12345678'
notify { "Test: #{test[-3,3]}": }

[szponek@szponek tmp]$ puppet apply test1.pp 
Notice: Compiled catalog for szponek.example.net in environment production in 0.01 seconds
Notice: Test: #{test[-3,3]}
Notice: /Stage[main]/Main/Notify[Test: #{test[-3,3]}]/message: defined 'message' as 'Test: #{test[-3,3]}'
Notice: Applied catalog in 0.02 seconds

'$' works as expected so maybe [8-,8] construct is just not supported on puppet < 4.x

[szponek@szponek tmp]$ cat test1.pp 

$test='12345678'
notify { "Test: ${test[-3,3]}": }

[szponek@szponek tmp]$ puppet apply test2.pp 
Notice: Compiled catalog for szponek.example.net in environment production in 0.02 seconds
Notice: Test: 678
Notice: /Stage[main]/Main/Notify[Test: 678]/message: defined 'message' as 'Test: 678'
Notice: Applied catalog in 0.02 seconds

Copy link
Member

@truthbk truthbk Dec 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right. Too much chef for me lately. I'll see what I can come up with that works across all versions... I think I can maybe use regsubst for this.

@truthbk
Copy link
Member

truthbk commented Dec 12, 2017

Closing in favor of #374, based off this PR, but different approach. Thank you @szponek!

@truthbk truthbk closed this Dec 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ubuntu::install_key should not continuously install repository keys
2 participants