解决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

这是初始化。模块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常见的代码片段(文件语句)和在另一个manifest的exec语句,但当我调用多次模块deploy_artifacts它抛出我相同的重复错误。

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

是否有另一个解决方案,而不是声明一个专用类的文件?谢谢你!

试试这个:

文件:

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',
    }
}

最新更新