Puppet Duplicate declaration: Class[main] is already declared - puppet

I am trying to setup my puppet modules and apply. And I get the below error:
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Class[main] is already declared; cannot redeclare (file: /mnt/wso2puppet/dev/manifests/site.pp, line: 24) (file: /mnt/wso2puppet/dev/manifests/site.pp, line: 24, column: 3) on node test-mi-integrator
And here's my /mnt/wso2puppet/dev/manifests/site.pp
...
# Run stages
stage { 'custom': }
# Order stages
Stage['main'] -> Stage['custom']
node default {
class { "::${::profile}": }
class { "::${::profile}::custom":
stage => 'custom'
}
}
Can someone help me what is wrong here?

Related

When sending the configuration to the puppet agent, I get an error

When sending the configuration to the agent, I get an error Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, no implicit conversion of String into Integer (file:/etc/puppetlabs/code/environments/production/modules/accounts/manifests/init.pp, line: 24, column: 24) on node
init.pp
**# See README.md for details.**
class accounts(
$groups = {},
$groups_membership = undef,
$ssh_keys = {},
$users = {},
$usergroups = {},
$accounts = {},
$start_uid = undef,
$start_gid = undef,
$purge_ssh_keys = false,
$ssh_authorized_key_title = '%{ssh_key}-on-%{account}',
$shell = undef,
$managehome = true,
$forcelocal = true,
) {
include ::accounts::config
create_resources(group, $groups)
create_resources(accounts::account, $accounts)
** # Remove users marked as absent**
$absent_users = keys(absents($users))
user { $absent_users:
ensure => absent,
managehome => $managehome,
forcelocal => $forcelocal,
}
}
_______________________________________________________________________________________________
I'm new to puppet and using it together with foreman
Puppet master version 7.2.0
Puppet agent version 6.27.0
Foreman version 3.4.0
All settings were made in Foreman. Manifests, like any other changes, were not made in the console.

Getting "error TS2307: Cannot find module" when deploynig code using ml-gradle

When I trying to deploying the code on ml server(10.0-9.4) ,with below build.gradle file , we are getting the below mentioned error:
In this deployment, I want to avoid the loading of ts(src/test/rule10.test.ts) file , is there any way to do so as it is not required and dependent on other modules.
command used :
./gradlew -b build.gradle loadRules -i -PmlUsername="" -PmlPassword="" -PmlHost="localhost"
build.gradle
plugins {
// node
// id "com.moowork.node" version "1.1.1"
// ML-Gradle will handle the marklogic configuration
id 'com.marklogic.ml-gradle' version '4.1.0'
id "com.github.node-gradle.node" version "3.1.1"
}
// Set up extra properties to configure ml-gradle
ext {
// set up the default IDDN databases
mlAppConfig {
contentDatabaseName = 'data1'
schemasDatabaseName = 'Schemas'
modulesDatabaseName = 'Modules'
triggersDatabaseName = 'Triggers'
}
mlAppDeployer.getCommand('DeployCustomForestsCommand').setCustomForestsPath("forests")
// mlAppDeployer.getCommands().remove(mlAppDeployer.getCommand("DeployRolesCommand"))
// do not let ml-gradle create a default rest server - we will only use the json config files
mlAppDeployer.getCommands().remove(mlAppDeployer.getCommand('DeployRestApiServersCommand'))
}
repositories {
mavenCentral()
// Needed for mlcp dependencies
maven { url 'https://developer.marklogic.com/maven2/' }
}
configurations {
mlcp
}
dependencies {
mlcp 'com.marklogic:mlcp:10.0.9.2'
mlcp files('lib')
}
// Control nodejs and NPM build tasks via gradle
node {
// Version of node to use.
version = '10.14.1'
npmVersion = '6.4.1'
download = true
}
// do not spam NPM error messages, the tools' own messages are fine.
npm_run_clean {
args = ['--loglevel', 'silent']
}
npm_run_build {
args = ['--loglevel', 'silent']
}
npm_run_test {
args = ['--loglevel', 'silent']
}
task loadJSON(type: com.marklogic.gradle.task.MlcpTask, dependsOn: []) {
classpath = configurations.mlcp
command = 'IMPORT'
database = 'Modules'
input_file_path = './src/main/ml-modules/root/a1.json'
document_type = 'json'
output_uri_replace = "^.*root,''"
}
// temp workaround to facilitate ns and collections
task loadJS(type: com.marklogic.gradle.task.MlcpTask, dependsOn: [npm_run_clean, npm_run_build]) {
classpath = configurations.mlcp
command = 'IMPORT'
database = 'Modules'
input_file_path = './src/main/ml-modules/root'
document_type = 'text'
output_uri_replace = "^.*root,''"
}
task loadRules(type: com.marklogic.gradle.task.MlcpTask, dependsOn: [mlClearModulesDatabase, mlClearSchemasDatabase, mlLoadSchemas, loadJS, loadJSON]) {
classpath = configurations.mlcp
command = 'IMPORT'
database = 'Modules'
input_file_path = './src/main/ml-modules/root'
document_type = 'text'
output_uri_replace = "^.*root,''"
output_uri_suffix = ".sjs"
}
mlLoadSchemas.mustRunAfter(mlClearSchemasDatabase)
npm_run_build{}.mustRunAfter(npm_run_clean)
loadJS.mustRunAfter(npm_run_build)
loadJS.mustRunAfter(mlClearModulesDatabase)
loadJSON.mustRunAfter(loadJS)
loadRules.mustRunAfter(loadJS)
error:
> Task :npm_run_build
Caching disabled for task ':npm_run_build' because:
Build cache is disabled
Task ':npm_run_build' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Starting process 'command '/var/opt/redaction/.gradle/npm/npm-v6.4.1/bin/npm''. Working directory: /var/opt/redaction Command: /var/opt/redaction/.gradle/npm/npm-v6.4.1/bin/npm run build --loglevel silent
Successfully started process 'command '/var/opt/redaction/.gradle/npm/npm-v6.4.1/bin/npm''
src/test/rule12.test.ts(3,38): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule11.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule10.test.ts(2,38): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/test7.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/test5.ts(3,36): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule3.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule2.test.ts(2,38): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule1.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
> Task :npm_run_build FAILED
:npm_run_build (Thread[Execution worker for ':',5,main]) completed. Took 3.295 secs.
Please any one can help me on this.
You could look to apply properties to only include (or to exclude) certain module filename patterns:
https://github.com/marklogic-community/ml-gradle/wiki/Property-reference#module-and-schema-properties
mlModulesRegex New in 3.3.0 - when running mlLoadModules or mlReloadModules, only load modules with a file path matching the given regex pattern. No default value.
mlResourceFilenamesToExcludeRegex New in 3.0.0 - regex that defines resource filenames to exclude from processing (exclude = ignore). Useful for when you want to exclude a set of resources when deploying to a certain environment. Cannot be set when mlResourceFilenamesToIncludeRegex is also set. No default value.

looping in Puppet 5 results in duplicate declaration error

Request some help please.
Requirement is to create a custom firewall service and then allow this custom firewall service only to a selected ips (trying to use firewalld_rich_rules here).
Here is the sample code:
class foo::fwall (
$sourceip = undef,
)
{
include firewalld
if $sourceip {
$sourceip.each |String $ipaddr| {
firewalld_rich_rule { "rich_rule_${ipaddr}":
ensure => enabled,
permanent => true,
zone => 'public',
family => ipv4,
source => $ipaddr,
element => service,
servicename => 'bar',
action => accept,
}
}
}
# this is defined in firewalld class and works good
firewalld::custom_service { 'bar':
short => 'bar custom service',
description => 'custom service ports',
ports => [
{
port => '7771',
protocol => 'tcp',
},
{
port => '8282',
protocol => 'tcp',
},
{
port => '8539',
protocol => 'tcp',
},
],
}
}
and while running it on a node, with couple of ip addresses (provided as an array for $sourceip), it results in duplicate declaration error
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Firewalld_rich_rule[rich_rule_2] is already declared at (file: .../dev/modules/test/manifests/fwall.pp, line: 11); cannot redeclare (file: .../dev/modules/test/manifests/fwall.pp, line: 11) (file: .../dev/modules/test/manifests/fwall.pp, line: 11, column: 7) on node server.domain
Trying it in puppet v5.5 (from puppetlabs) for Redhat Enterprise Linux 7 servers
Note: tried defining a resource following this example from Puppet documentation but getting invalid address error.
define puppet::binary::symlink ($binary = $title) {
file {"/usr/bin/${binary}":
ensure => link,
target => "/opt/puppetlabs/bin/${binary}",
}
}
Use the defined type for the iteration somewhere ele in your manifest file:
$binaries = ['facter', 'hiera', 'mco', 'puppet', 'puppetserver']
puppet::binary::symlink { $binaries: }
I had to change the datatype for $sourceip to array in RH Satellite's smart class parameters which was String by default. Everything works good now.

Hiera value not able to receiving in puppet profile

I have created a proxy_match.yaml file as a hiera source file in
default hiera datalocation.
The proxy_match.yaml is added in hiera hierarchy
Looking up hiera data in profile
Where and what am I missing, I am not able to receive the hiera data
value and thus the error appears mentioned bellow.
Where,
proxy_match is the new environment created
hierafile 1
/etc/puppetlabs/code/environments/proxy_match/hiera.yaml
version: 5
defaults:
# The default value for "datadir" is "data" under the same directory as the hiera.yaml
# file (this file)
# When specifying a datadir, make sure the directory exists.
# See https://docs.puppet.com/puppet/latest/environments.html for further details on environments.
# datadir: data
# data_hash: yaml_data
hierarchy:
- name: "environment specific yaml"
path: "proxy_match.yaml"
- name: "Per-node data (yaml version)"
path: "nodes/%{::trusted.certname}.yaml"
- name: "Other YAML hierarchy levels"
paths:
- "common.yaml"
proxy_match.yaml hiera data source file
This is the yaml hiera source named as proxy_match.yaml as in herarchy
/etc/puppetlabs/code/environments/proxy_match/data/proxy-match.yaml
---
profiles::apache::servername: "taraserver.com"
profiles::apache::port: "80"
profiles::apache::docroot: "/var/www/tarahost"
hiera lookup in profile
$servername = hiera('profiles::apache::servername',{})
$port = hiera('profiles::apache::port',{})
$docroot = hiera('profiles::apache::docroot',{})
class profile::apache{
#configure apache
include apache
apache::vhost{$servername:
port => $port,
docroot => $docroot,
}
}
#ERROR:
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: {"message":"Server Error: Evaluation Error: Error while evaluating a Resource Statement, Apache::Vhost[7fba80ae621c.domain.name]: parameter 'docroot' expects a value of type Boolean or String, got Undef at /etc/puppetlabs/code/environments/proxy_match/modules/profile/manifests/apache.pp:29 on node 94707b03ff05.domain.name","issue_kind":"RUNTIME_ERROR"}
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
You are defining the variables outside the class definition. When Puppet loads that class, those lines you have before the class are ignored.
What you should have in your profile class is:
class profiles::apache (
String $servername,
Integer $port,
String $docroot,
) {
include apache
apache::vhost { $servername:
port => $port,
docroot => $docroot,
}
}
Note that I used the automatic parameter lookup feature to set your variables, instead of explicit calls to the hiera function.

Only classes can set 'stage'; normal resources like XXX cannot change run stage

I have a manifest where a package depends on an apt::source resource. I've tried to make sure the apt::source runs first by setting a stage:
include apt
stage { 'first':
before => Stage['main']
}
apt::source { 'erlang_repo':
location => 'http://packages.erlang-solutions.com/ubuntu',
repos => 'contrib',
key => 'A14F4FCA',
stage => first
}
package { 'erlang':
ensure => '1:17.3'
}
However, I'm hitting the following error:
==> default: Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Only classes can set 'stage'; normal resources like Apt::Source[erlang_repo] cannot change run stage at /tmp/manifests/default.pp:12 on node vagrant-ubuntu-trusty-64.home
==> default: Wrapped exception:
==> default: Only classes can set 'stage'; normal resources like Apt::Source[erlang_repo] cannot change run stage
==> default: Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Only classes can set 'stage'; normal resources like Apt::Source[erlang_repo] cannot change run stage at /tmp/manifests/default.pp:12 on node vagrant-ubuntu-trusty-64.home
Any pointers will be appreciated.
If you really want to use stages, you should wrap the appropriate resources in (possibly dedicated) classes.
class site::apt_sources {
apt::source { ... }
}
and declare it like
class { 'site::apt_sources': stage => first }
Please note that the use of stages is discouraged.
If you don't use virtual resources, you can probably achieve the desired effect through this relationship instead:
Apt::Source<| |> -> Package<| |>
I decided to go with this in the end:
include apt
Apt::Pin <| |> -> Package <| |>
Apt::Source <| |> -> Package <| |>
apt::source { 'erlang_repo':
location => 'http://packages.erlang-solutions.com/ubuntu',
repos => 'contrib',
key => 'A14F4FCA'
}
package { 'erlang':
ensure => '1:17.3',
}

Resources