简体   繁体   English

在文件,类和定义之间创建关系的人偶

[英]puppet creating relationship between file, class and define

I want to create relationship between file, class and define.... Please check the below code.... The problem I am facing is, even if there is no change in deploy.cfg file, class and nexus::artifact always runs... 我想在文件,类和定义之间创建关系。...请检查下面的代码....我面临的问题是,即使deploy.cfg文件,类和nexus :: artifact始终没有变化运行...

class and nexus::artifact should execute only if it detects a change in file class和nexus :: artifact仅在检测到文件更改后才执行

I know that we need to make use of subscribe and refreshonly=true. 我知道我们需要使用subscribe和refreshonly = true。 But I have no idea where to put this... 但是我不知道该放在哪里...

 file { 'deploy.cfg':
    ensure  => file,
    path    => '/home/deploy/deploy.cfg',
    mode    => '0644',
    owner   => 'root',
    group   => 'root',
    content => "test",
    notify  => [Class['nexus'], Nexus::Artifact['nexus-artifact']],
    subscribe => File['/home/deploy/dir'],
  }

  class { 'nexus':
    url      => $url,
    username => $user,
    password => $password,
  }

  nexus::artifact { "nexus-artifact":
    gav        => $gav,
    packaging  => $packaging,
    output     => $targetfilepath,
    repository => $repository,
    owner      => $owner,
    mode       => $mode,
  }

artifact.pp 人工制品

define nexus::artifact (
  $gav,
  $repository,
  $output,
  $packaging  = 'jar',
  $classifier = undef,
  $ensure     = update,
  $timeout    = undef,
  $owner      = undef,
  $group      = undef,
  $mode       = undef
) {
    include nexus
}

init.pp 初始化文件

class nexus (
  $url,
  $username = undef,
  $password = undef,
  $netrc = undef,
) {
}

even if there is no change in deploy.cfg file, class and nexus::artifact always runs 即使deploy.cfg文件没有任何更改,class和nexus :: artifact也始终运行

Well yes, every class and resource in your node's catalog is applied on every catalog run, unless a resource that is required to be applied before it fails. 好吧,是的,节点目录中的每个类和资源都将在每次运行的目录中应用,除非需要在资源失败之前应用该资源。 That is normal. 那很正常。 The key thing to understand in this regard is that the first part of applying a catalog resource is determining whether the corresponding physical resource is already in sync; 在这方面要理解的关键是,应用目录资源的第一部分是确定相应的物理资源是否已经同步。 if it is, then applying the catalog resource has no further effect. 如果是这样,则应用目录资源没有进一步的影响。

class and nexus::artifact should execute only if it detects a change in file class和nexus :: artifact仅在检测到文件更改后才执行

I know that we need to make use of subscribe and refreshonly=true. 我知道我们需要使用subscribe和refreshonly = true。

Well, no. 好吧,不。 You may be able to modulate the effect of applying that class and resource, but you cannot use the result of syncing another resource to modulate whether they are applied at all. 您可能可以调节应用该类和资源的效果 ,但是您不能使用同步另一个资源的结果来调节它们是否完全应用。 In any event, refreshonly is specific to Exec resources, and you don't have any of those in your code. 无论如何, refreshonly特定于Exec资源,并且您的代码中没有任何资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM