1

I'm trying to call several times a defined instance of a puppet module to deploy multiple files from a given repository but I'm getting this error:

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

This is the init.pp manifest of the module:

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;
    }
}

Now the node manifest:

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

}

I tried to rewrite the whole module to put into init.pp the common piece of code(file statement) and in another manifest the exec statement but when I call more than once the module deploy_artifacts it throws me the same duplicated error.

How can I rewrite the code to ensure that the file is in the client node before executing all the instances of the defined deploy_artifacts without duplications?

Is there another solution rather than declare a dedicated class only for the file? Thank you!

1 Answers1

2

Try this:

The file:

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

The type:

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"
  }
}

The node definition:

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

}
ptierno
  • 9,534
  • 2
  • 23
  • 35
  • hmmm... I think there is a small nit: `exec {"Deployment":` should be `exec {"Deployment $name":` so the exec resource us unique. – Russell Fulton Aug 28 '22 at 00:23
  • @RussellFulton It has been a very long time since using puppet. but wouldint the "define" sort of encapsulate that exec? – ptierno Mar 09 '23 at 03:44