How to write a manifest for puppet to check if the nginx package is installed, and if installed, then create a file?

I tried something like this:

if ! defined(Package['nginx-full']) { file { "/opt/puppet/test_nginx4.tmp": ensure => "present", owner => "root", group => "root", mode => '664', } } 
  • one
    I don’t know the answer, but I approve the topic)) - Nick Volynkin

1 answer 1

Solved this problem in the following way:

class base :: nginx {

  file { "vim_nginx": ensure => 'present', path => '/tmp/puppet/vim_nginx.sh', source => 'puppet:///modules/base/vim_nginx.sh', mode => '774', } exec { "highlighting": command => 'bash /tmp/puppet/vim_nginx.sh', path => "/usr/bin:/usr/sbin:/bin", require => File['vim_nginx'], onlyif => 'test -e /etc/nginx/nginx.conf' } 

}

Those. here I created a script that sets syntax highlighting, is copied to all servers belonging to a given class. Next, the test for the presence of the /etc/nginx/nginx.conf file works, which confirms whether nginx is installed or not. If yes, then run the script.

In principle, this can be used with any other dependencies or even improve the logic of work.