解决人偶上的重复声明

Resolve duplicate declaration on puppet

我试图多次调用 puppet 模块的已定义实例以从给定存储库部署多个文件,但出现此错误:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: File[/bin/deploy_artifacts.rb] is already declared in file /etc/puppet/modules/deploy_artifacts/manifests/init.pp:11; cannot redeclare at /etc/puppet/modules/deploy_artifacts/manifests/init.pp:11 on node node.example.com

这是模块的 init.pp 清单:

define deploy_artifacts (
 $repository)
{
    notify{"La UUAA esta en el repositorio: $repository": }
    file { "/bin/deploy_artifacts.rb":
            ensure  => present,
            owner   => root,
            group   => root,
            mode    => 700,
            source  => "puppet:///modules/deploy_artifacts/deploy_artifacts.rb";
    }
    exec {"Deployment":
            require => File["/bin/deploy_artifacts.rb"],
            command => "/usr/bin/time /bin/deploy_artifacts.rb $repository",
            logoutput => true;
    }
}

现在节点清单:

node "node.example.com" {
    deploy_artifacts {'test-ASO':
            repository => 'test-ASO',
    }
    deploy_artifacts {'PRUEBA_ASO':
            repository => 'PRUEBA_ASO',
    }

}

我试图重写整个模块以放入 init.pp 通用代码段(文件语句)并在另一个清单中放入 exec 语句但是当我多次调用模块时 deploy_artifacts它抛出同样的重复错误。

如何重写代码以确保在执行定义的 deploy_artifacts 的所有实例之前文件在客户端节点中而不重复?

是否有其他解决方案而不是为文件声明专用 class?谢谢!

试试这个:

文件:

class deploy_artifacts {
  file { "/bin/deploy_artifacts.rb":
    ensure  => present,
    owner   => root,
    group   => root,
    mode    => 700,
    source  => "puppet:///modules/deploy_artifacts/deploy_artifacts.rb";
  }
}

类型:

define deploy_artifacts::repository ($repository) {
  include deploy_artifacts

  exec {"Deployment":
    command => "/usr/bin/time /bin/deploy_artifacts.rb $repository",
    logoutput => true,
    require => File["/bin/deploy_artifacts.rb"
  }
}

节点定义:

node "node.example.com" {
    deploy_artifacts::repository {'test-ASO':
            repository => 'test-ASO',
    }
    deploy_artifacts::repository {'PRUEBA_ASO':
            repository => 'PRUEBA_ASO',
    }

}