Проверка конкретной версии + цикл if и else

898
user3331457

просто начни марионетку. Как все знают, начинать что-либо всегда труднее всего. Для практики я хочу сделать следующее: я полагаю, что я должен поместить его в init.pp.

if 'openssl' version == '1.0.2b' or '1.0.2d' upgrade to 1.1.1e else do nothing 

В настоящее время мой код выглядит так

 package { 'openssl': if 'openssl' version == '1.0.2b' or '1.0.2d' { ensure => '1.1.1e' } else { } 

У меня есть несколько проблем:

1) Я не думаю, что мой синтаксис для версии openssl написан правильно. Когда я делаю простой поиск в Google, я вижу людей, которые обеспечивают версию openssl примерно так: «1.0.1e-15.el6», иногда это «1.0.1e-16.el6_5.7». Я не понимаю, что следует за «-».

2) Я не думаю, что ввод "openssl" заставит кукол знать, что это openssl

3) Как проверить версию openssl? Я думаю, что мой синтаксис if 'openssl' version == 'xxx'не правильный.

2

1 ответ на вопрос

0
spuder

There are couple of things you could do to approach this problem which will make your code better in the long run.

  1. Use the stdlib library which has improved string comparison operations, such as versioncmp(). It will work properly with version strings that have decimals and letters.

 if versioncmp($::puppetversion, '3.0.0') < 0 { fail("foobar requires puppet 3.0.0 or greater, found: \'${::puppetversion}\'") } 

  1. Don't do your conditional statements inside of your resource. At the very least split them out so they are at the top of your manifest. (Untested code)

if versioncmp( '$openssl', '1.1.3e') < 0 { $openssl_version = '42' } package {'openssl': ensure => "$openssl_version", } 

Though, you have to ask yourself, is this really what you want to do? Puppet best practices are that your business requirements should not be part of your base modules. They should be abstracted to roles/profiles modules or with hiera. You may be better off with the following options.

A. Just make sure all your servers are up to date

package {'openssl': ensure => latest, } 

B. If you have some nodes, that just must use an older/insecure version. Then make a parameterized class, and override the openssl_version parameter with hiera or role/profile.

Additional information

https://puppetlabs.com/blog/patching-heartbleed-openssl-vulnerability-puppet-enterprise http://garylarizza.com/blog/2014/02/17/puppet-workflow-part-2/