Hi avenk
I think you just need to change from declaring *undef* to using an empty
array. The code will throw the error where the class is *NOT called* with
*$enable_ipv6_localhost
= true*,
Change:
*$my_localhost6_aliases = undef*
to
*$my_localhost6_aliases = []*
As your own code is throwing the error:
*if !is_string($my_localhost6_aliases) and
!is_array($my_localhost6_aliases) {*
* fail('hosts::localhost6_aliases must be a string or an array.')*
* }*
*undef* is not a string and it is not an array.
I hope this solves the issue for you.
On Friday, May 14, 2021 at 3:45:30 PM UTC+1 [email protected] wrote:
> Hi all,
>
> PE server version : PE 2019.8.5
> Puppet agent version : 6.21.1
>
> Actually i have added profile class which calls hosts class and pass
> parameters to it .Then its been assigned to individual nodegroup on
> console .
> we were facing below 500 error while puppet agent run and that looks like
> validation of parameter as string .
>
> I suspect this could be of Undef parameter validation but not sure what
> could be rectify this issue .
>
> Can someone help me on what could be the error ?
>
> Profile class :
> --------------------
> class profile::ldap_hosts () {
>
>
>
> class { '::hosts':
>
> host_entries => {
>
> "ldaps1-dev.com.net" => { ensure => 'absent' },
>
> "ldaps2-dev.com.net " => { ensure => 'absent' },
>
> " ldaps3-dev.com.net " => { ensure => 'absent' },
>
> " ldaps4-dev.com.net " => { ensure => 'absent' },
>
> }
>
> }
>
>
>
> }
> hosts class :
>
> # == Class: hosts
>
> #
>
> # Manage /etc/hosts
>
> #
>
> class hosts (
>
> $collect_all = false,
>
> $enable_ipv4_localhost = true,
>
> $enable_ipv6_localhost = false,
>
> $enable_fqdn_entry = false,
>
> $use_fqdn = true,
>
> $fqdn_host_aliases = $::hostname,
>
> $localhost_aliases = ['localhost',
>
> 'localhost4',
>
> 'localhost4.localdomain4'],
>
> $localhost6_aliases = ['localhost6',
>
> 'localhost6.localdomain6'],
>
> $purge_hosts = false,
>
> $target = '/etc/hosts',
>
> $host_entries = undef,
>
> ) {
>
>
>
>
>
> # validate type and convert string to boolean if necessary
>
> if is_string($collect_all) {
>
> $collect_all_real = str2bool($collect_all)
>
> } else {
>
> $collect_all_real = $collect_all
>
> }
>
>
>
> # validate type and convert string to boolean if necessary
>
> if is_string($enable_ipv4_localhost) {
>
> $ipv4_localhost_enabled = str2bool($enable_ipv4_localhost)
>
> } else {
>
> $ipv4_localhost_enabled = $enable_ipv4_localhost
>
> }
>
>
>
> # validate type and convert string to boolean if necessary
>
> if is_string($enable_ipv6_localhost) {
>
> $ipv6_localhost_enabled = str2bool($enable_ipv6_localhost)
>
> } else {
>
> $ipv6_localhost_enabled = $enable_ipv6_localhost
>
> }
>
>
>
> # validate type and convert string to boolean if necessary
>
> if is_string($enable_fqdn_entry) {
>
> $fqdn_entry_enabled = str2bool($enable_fqdn_entry)
>
> } else {
>
> $fqdn_entry_enabled = $enable_fqdn_entry
>
> }
>
>
>
> # validate type and convert string to boolean if necessary
>
> if is_string($use_fqdn) {
>
> $use_fqdn_real = str2bool($use_fqdn)
>
> } else {
>
> $use_fqdn_real = $use_fqdn
>
> }
>
>
>
> # validate type and convert string to boolean if necessary
>
> if is_string($purge_hosts) {
>
> $purge_hosts_enabled = str2bool($purge_hosts)
>
> } else {
>
> $purge_hosts_enabled = $purge_hosts
>
> }
>
>
>
> if $ipv4_localhost_enabled == true {
>
> $localhost_ensure = 'present'
>
> $localhost_ip = '127.0.0.1'
>
> $my_localhost_aliases = $localhost_aliases
>
> } else {
>
> $localhost_ensure = 'absent'
>
> $localhost_ip = '127.0.0.1'
>
> $my_localhost_aliases = undef
>
> }
>
>
>
> if $ipv6_localhost_enabled == true {
>
> $localhost6_ensure = 'present'
>
> $localhost6_ip = '::1'
>
> $my_localhost6_aliases = $localhost6_aliases
>
> } else {
>
> $localhost6_ensure = 'absent'
>
> $localhost6_ip = '::1'
>
> $my_localhost6_aliases = undef
>
> }
>
>
>
> if !is_string($my_localhost_aliases) and
> !is_array($my_localhost_aliases) {
>
> fail('hosts::localhost_aliases must be a string or an array.')
>
> }
>
>
>
> if !is_string($my_localhost6_aliases) and
> !is_array($my_localhost6_aliases) {
>
> fail('hosts::localhost6_aliases must be a string or an array.')
>
> }
>
>
>
> if $fqdn_entry_enabled == true {
>
> $fqdn_ensure = 'present'
>
> $my_fqdn_host_aliases = $fqdn_host_aliases
>
> $fqdn_ip = $::ipaddress
>
> } else {
>
> $fqdn_ensure = 'absent'
>
> $my_fqdn_host_aliases = []
>
> $fqdn_ip = $::ipaddress
>
> }
>
>
>
> Host {
>
> target => $target,
>
> }
>
>
>
> host { 'localhost':
>
> ensure => 'absent',
>
> }
>
>
>
> host { 'localhost.localdomain':
>
> ensure => $localhost_ensure,
>
> host_aliases => $my_localhost_aliases,
>
> ip => $localhost_ip,
>
> }
>
>
>
> host { 'localhost6.localdomain6':
>
> ensure => $localhost6_ensure,
>
> host_aliases => $my_localhost6_aliases,
>
> ip => $localhost6_ip,
>
> }
>
>
>
> if $use_fqdn_real == true {
>
> @@host { $::fqdn:
>
> ensure => $fqdn_ensure,
>
> host_aliases => $my_fqdn_host_aliases,
>
> ip => $fqdn_ip,
>
> }
>
>
>
> case $collect_all_real {
>
> # collect all the exported Host resources
>
> true: {
>
> Host <<| |>>
>
> }
>
> # only collect the exported entry above
>
> default: {
>
> Host <<| title == $::fqdn |>>
>
> }
>
> }
>
> }
>
>
>
> resources { 'host':
>
> purge => $purge_hosts,
>
> }
>
>
>
> if $host_entries != undef {
>
> $host_entries_real = delete($host_entries,$::fqdn)
>
> validate_hash($host_entries_real)
>
> create_resources(host,$host_entries_real)
>
> }
>
> }
> Agent error :
>
> May 14 08:59:48 dev-server puppet-agent[15635]: 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 Function Call, hosts::localhost6_aliases must be a string or
> an array. (file:
> /etc/puppetlabs/code/environments/production7/modules/hosts/manifests/init.pp,
>
> line: 90, column: 5) on node cagmp-sup19b3.cag.dyn.nsroot.net
>
> Regards,
>
> navenk
>
>
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/4c711b92-fae3-4a9a-a659-f9f22d3b2f0bn%40googlegroups.com.