Puppet DSC module: Could not evaluate: Convert property 'authenticationinfo' value from type 'INSTANCE[]' to type 'INSTANCE' failed - puppet

I'm attempting to use dsc_authenticationinfo => {"Anonymous"=>false, "Basic"=>false, "Digest"=>false, "Windows"=>true}, getting could not evaluate error below. This property is inside of dsc_xwebsite{}.
dsc_xwebsite{$app_dns_name:
dsc_ensure => 'Present',
dsc_name => $app_dns_name,
dsc_state => 'Started',
dsc_physicalpath => $app_webroot_path,
dsc_applicationpool => $app_pool_name,
dsc_bindinginfo => [{
protocol => 'HTTP',
port => 80,
hostname => $app_dns_name,
}],
dsc_authenticationinfo => {"Anonymous"=>true, "Basic"=>true, "Digest"=>true, "Windows"=>true},
}
I'm getting the following error on my windows 2012 R2 host.
Error: /Stage[main]/Profiles::Iis_tools/Dsc_xwebsite[tools-dev.domain.com]: Could not evaluate: Convert property 'authenticationinfo' value from type 'INSTANCE[]' to type 'INSTANCE' failed
At line:31, char:2
Buffer:
ls-dev.domain.com";
};^
insta

I'm not familiar with Puppet syntax, but comparing your puppet code to some working DSC below, it seems like your authentication code should be formatted more like your bind code, so
dsc_authenticationinfo =>
{"Anonymous"=>true, "Basic"=>true, "Digest"=>true, "Windows"=>true},
should be:
dsc_authenticationinfo =>
{dsc_anonymous => true, dsc_basic => true, dsc_digest => true, dsc_windows => true},
However, your error message:
"Convert property 'authenticationinfo' value from type 'INSTANCE[]' to
type 'INSTANCE' failed"
indicates you are passing an array when a single authenticationinfo is expected? Your dsc_authenticationinfo value is not in square brackets which looks correct to me; I'm hoping the code you posted and the error message are just out of sync, and the code change above will fix your issue.
For reference, this is valid DSC code. And note that BindingInfo is an array of one while AuthenticationInfo is a single instance:
xWebSite DefaultWebSite_Site
{
Name = "Default Web Site"
Ensure = "Present"
State = "Started"
ApplicationPool = "DefaultAppPool"
PhysicalPath = "%SystemDrive%\inetpub\wwwroot" # must already exist
LogPath = "D:\IISLogs"
DependsOn = "[xWebAppPool]DefaultAppPool_Pool"
BindingInfo =
#(
MSFT_xWebBindingInformation
{
Protocol = "http"
Port = "80"
IPAddress = "*"
}
)
AuthenticationInfo =
MSFT_xWebAuthenticationInformation
{
Anonymous = $true
Basic = $false
Digest = $false
Windows = $false
}
}

This was an issue with 1) documentation on Microsoft's DSC code. 2) Improper implementation in puppetlabs\dsc module. The MS documentation was fixed and the DSC module was fixed as of version 1.2.0.

Related

Puppet: Handling multiple resource attributes in generic way

For resources where only one or two attributes are changing, i can use array and hashes respectively. For example, if i have to create files in different directories, i can store the file names and respective paths in a hash and apply them by iterating over the hash. In case if i have more than two attributes that are different, how do i store and iterate over those attributes?
For example, i am trying to create Active Directory groups and i have five attributes and all are different for each group as shown below:
Group_Name Display Name Path Description GroupCategory
"My Support" "Support" "OU=Groups,OU=DEF,DC=xyz,DC=Com" "Some decription" Security
"Prod DBA" "DBA" "OU=Groups,OU=XYZ,DC=xyz,DC=Com" "Different description" Distribution
...
...
UPDATE: Based on the suggestion, here's the code:
[root#myhost] cat params.pp
$ad_groups = {
'Group_Prod' => {
path => 'OU=Groups,OU=PROD,DC=TEST,DC=COM',
displayname => 'Prod Support',
description => 'Prod Support',
},
'Group_App' => {
path => 'OU=Groups,OU=APP,DC=TEST,DC=COM',
displayname => 'App Support',
description => 'App Support',
},
}
$ad_groups_defaults = {
'ensure' => present,
'groupscope' => 'Global',
'groupcategory' => 'Security',
},
[root#myhost] cat create_groups.pp
class infra::ad::create_groups (
$ad_groups = $infra::params::ad_groups,
$ad_groups_defaults = $infra::params::ad_groups_defaults,
) inherits infra::params {
create_resources(windows_ad::group,$ad_groups,$ad_groups_defaults)
}
Now when i try running it, i am getting the following error:
Could not retrieve catalog from remote server: Error 500 on SERVER: "message":"Server Error: Evaluation Error: Error while evaluating a Resource Statement, Windows_ad::Group[Group_Prod]: default expression for $groupname tries to illegally access not yet evaluated $groupname at /etc/puppetlabs/code/environments/production/modules/infra/manifests/ad/create_groups.pp:5 on node puppet.test.com","issue_kind":"RUNTIME_ERROR"}
Now if i also add groupname attribute in each hash block, the error is resolved. What i want to know is that if my group names are same as the hash keys (in this case, Group_Prod and Group_App), then can i somehow use those hash keys itself as groupname without adding groupname attribute in each hash block?

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...
class and nexus::artifact should execute only if it detects a change in file
I know that we need to make use of subscribe and 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
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
I know that we need to make use of subscribe and 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.

conditional within define in puppet

Running Puppet 3.8
I have two defines:
define desktop::vinstall () {
package { $title:
ensure => installed,
allow_virtual => true,
configfiles => keep,
}
}
and
define desktop::vinstallwseeds () {
package { $title:
ensure => installed,
allow_virtual => true,
configfiles => keep,
require => File["/var/cache/debconf/pkg-${title}.seeds"],
responsefile => "/var/cache/debconf/pkg-${title}.seeds",
}
file { "/var/cache/debconf/pkg-${title}.seeds":
source => "puppet:///modules/desktop/pkg-${title}.seeds",
ensure => present,
}
}
Would like to turn these into one define statement with an optional boolean argument, something like:
define desktop::vinstallopt ( $queryresponse = 'false', ) {
package { $title:
ensure => installed,
allow_virtual => true,
configfiles => keep,
if $queryresponse == 'true' {
require => File["/var/cache/debconf/pkg-${title}.seeds"],
responsefile => "/var/cache/debconf/pkg-${title}.seeds",
}
}
file { "/var/cache/debconf/pkg-${title}.seeds":
source => "puppet:///modules/desktop/pkg-${title}.seeds",
ensure => present,
}
}
and then instantiate it with statements like this one in init.pp:
#desktop::vinstallopt { 'gdebi': queryresponse => 'false', }
But doing so gives an error:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Puppet::Parser::AST::Resource failed with argument error ArgumentError: Invalid resource type desktop::vinstallopt at /etc/puppet/modules/desktop/manifests/init.pp:40 on node machine.prvt.net
where line 40 has the syntax above. I'm a newbie with puppet, so my apologies if this turns out the be a simple syntax question. I've tried to find a way to make this work from the PuppetLabs documentation and from other puppet users, so far without luck.
You are trying to embed an if block inside a resource declaration. Alas, this is not possible. The block must be global or in a regular block (e.g., class body, define body, lambda body).
In this case, you want to "amend" the package resource, so to speak. I like to use the following construct for this purpose:
package { $title:
ensure => installed,
allow_virtual => true,
configfiles => keep,
}
if $queryresponse {
Package[$title] {
require => File["/var/cache/debconf/pkg-${title}.seeds"],
responsefile => "/var/cache/debconf/pkg-${title}.seeds",
}
}
Please note that this override syntax is only allowed in this scope because the require and responsefile attributes don't have any value assigned originally.

Puppet relationship with a Hash

I would like to run the following code in a sequential order so that the servers_string variable is computed before the script execution.
Unfortunately puppet failed with the following error :
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Illegal relationship operand, can not form a relationship with a Hash. A Catalog type is required.
The code snippet :
$servers = [{ name => 'toto', ip => '10.0.0.1'}, { name => 'titi', ip => '10.0.0.2' }]
$servers.each | Hash $server | {
if $servers_string != "" {
$servers_string = "${servers_string},"
}
$name = $server['name']
$servers_string = "${servers_string}${name}"
}->
file { '/my/path/myscript.sh':
ensure => file,
mode => '0700',
owner => 'root',
group => 'root',
source => "puppet:///modules/${module_name}/install.sh --servers '${servers_string}'"
}
Any idea ? Thanks
Resource relationships in general and the chain operators in particular are about the order in which resources are applied to the node. They have nothing whatever to do with the order in which the catalog builder evaluates manifest files.
Manifests are always evaluated in order, left-to-right, top-to-bottom. You do not need to use chain operators to ensure that, nor can you use them to change it. Just drop the chain operator, and you'll be fine (at least in this regard).

create whmcs domain registrar module to sell domains with the tld of my country

Hi everyoneI have a site with whmcs and i want to sell domains with the tld of my county that is .al and i've searched the web for this but all told me that i need to create a domain registrar module.I'v downloaded the template from the whmcs site but i don't know how to use it.Does anyone have any idea how can i achieve this.
<?php
function template_getConfigArray() {
$configarray = array(
"Username" => array( "Type" => "text", "Size" => "20", "Description" => "Enter your username here", ),
"Password" => array( "Type" => "password", "Size" => "20", "Description" => "Enter your password here", ),
"TestMode" => array( "Type" => "yesno", ),
);
return $configarray;
}
function template_GetNameservers($params) {
$username = $params["Username"];
$password = $params["Password"];
$testmode = $params["TestMode"];
$tld = $params["tld"];
$sld = $params["sld"];
# Put your code to get the nameservers here and return the values below
$values["ns1"] = $nameserver1;
$values["ns2"] = $nameserver2;
$values["ns3"] = $nameserver3;
$values["ns4"] = $nameserver4;
# If error, return the error message in the value below
$values["error"] = $error;
return $values;
}
function template_SaveNameservers($params) {
$username = $params["Username"];
$password = $params["Password"];
$testmode = $params["TestMode"];
$tld = $params["tld"];
$sld = $params["sld"];
$nameserver1 = $params["ns1"];
$nameserver2 = $params["ns2"];
$nameserver3 = $params["ns3"];
$nameserver4 = $params["ns4"];
# Put your code to save the nameservers here
# If error, return the error message in the value below
$values["error"] = $error;
return $values;
}
function template_GetRegistrarLock($params) {
$username = $params["Username"];
$password = $params["Password"];
$testmode = $params["TestMode"];
$tld = $params["tld"];
$sld = $params["sld"];
# Put your code to get the lock status here
if ($lock=="1") {
$lockstatus="locked";
} else {
$lockstatus="unlocked";
}
return $lockstatus;
}
function template_SaveRegistrarLock($params) {
$username = $params["Username"];
$password = $params["Password"];
$testmode = $params["TestMode"];
$tld = $params["tld"];
$sld = $params["sld"];
if ($params["lockenabled"]) {
$lockstatus="locked";
} else {
$lockstatus="unlocked";
}
# Put your code to save the registrar lock here
# If error, return the error message in the value below
$values["error"] = $Enom->Values["Err1"];
return $values;
}
This is a part of the code from the module template.
Well the first step would be determining which registrar you are going to use to register your domains. There are quite a few that already have modules pre-built and included in WHMCS. You can see the list here.
If you are using a registrar that does not already have a pre-built module in WHMCS, then you will need to create your own. The template you downloaded has all of the supported functions in WHMCS. Before you roll out your own module however, you will want to see if your registrar has an API. If they do not then building the module for WHMCS is pointless. If they do, read through their documentation. Once you are familiar with the registrar's functionality, then it's just a matter of connecting the dots between the WHMCS template you downloaded and the registrar's API.
Best of luck!

Resources