Skip to content

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

Closed
szponek wants to merge 1 commit intoDataDog:masterfrom
szponek:fix-apt-key-continuous-exec
Closed

Only grep for last 8 characters as this is what apt-key list returns#373
szponek wants to merge 1 commit intoDataDog:masterfrom
szponek:fix-apt-key-continuous-exec

Conversation

@szponek
Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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.

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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