Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W.I.P. PR2: New functions created to query for each item - calling of functions in importer.pp #10

Merged
merged 23 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions functions/get_postgres_hosts.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function rsan::get_postgres_hosts() {
if $settings::storeconfigs {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes this whole thing conditional on $settings::storeconfigs, which is a snippet from another place in code this was copied from. This does not need to be conditional

$postgres_hosts =
puppetdb_query('resources[certname] {
type = "Class" and
title = "pe_postgresql::server::install" and
nodes {
deactivated is null and
expired is null
}
}').map |$data| { $data['certname'] }
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as there is no longer a conditional the exception of not having a postgres host returned needs handled differently

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Marty, would this mean I need to implement some sort of error catch? So if puppetdb_query returns nothing/an error - make an exception to set

$postgres_hosts = []

$postgres_hosts = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$postgres_hosts would need to be returned in a format
puppet_metrics_dashboard:: postgres_host_list expects

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in this case, puppet_metrics_dashboard::postgres_host would need to be an array of elements, with each element being a postgres host. I've been looking at https://puppet.com/docs/puppet/7.0/lang_data_type.html

Initially, part of me thinks that I need to some thing like:

function rsan::get_postgres_hosts() {
    $postgres_hosts => Array #this is the bit im thinking of adding in
    $postgres_hosts =
                puppetdb_query('resources[certname] {
                    type = "Class" and
                    title = "Pe_postgresql::Server::Install" and
                    nodes {
                      deactivated is null and
                      expired is null
                    }
                  }').map |$data| { $data['certname'] }
  }

My thinking is that by setting the data type beforehand - puppetdb_query will fill in the elements to that array as appropriate?

But I've also come across https://puppet.com/docs/puppet/7.0/lang_data_type.html#lang_data_type_usage

Where there is the 'Type' function. In this instance, I would do something like get the data type from the $postgres_hosts after the puppetdb_query is finished, then if the data type of $postgres_hosts =/ array, I set it as so?

}

pe_sort($postgres_hosts)

}
11 changes: 11 additions & 0 deletions functions/get_puppet_servers.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function rsan::get_puppet_servers() {
$puppet_servers =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a syntax issue here, best PDK validate

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syntax issue on this should be solved in my next commit from my local repo :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$puppet_servers needs to be in a format

puppet_metrics_dashboard::master_list expects

puppetdb_query('nodes[certname] {
resources {
type = "Class" and
title = "Puppet_enterprise::Profile::Master"
} and deactivated is null and expired is null }').map |$node| {
$node['certname']
}
pe_sort($puppet_servers)
}
17 changes: 17 additions & 0 deletions functions/get_puppetdb_hosts.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function rsan::get_puppetdb_hosts() {
if $settings::storeconfigs {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments on the condition here

$puppetdb_hosts =
puppetdb_query('resources[certname] {
type = "Class" and
title = "Puppet_enterprise::Profile::Puppetdb" and
nodes {
deactivated is null and
expired is null
}
}').map |$data| { $data['certname'] }
} else {
$puppetdb_hosts = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

puppetdb_hosts has to be returned in the correct format for

puppet_metrics_dashboard::puppetdb_list

}

pe_sort($puppetdb_hosts)
}
31 changes: 21 additions & 10 deletions manifests/importer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,27 @@
################### 3. Telemetry dashboard ########################################
# If using puppet_metrics_dashboard:

# class { 'puppet_metrics_dashboard':
# add_dashboard_examples => true,
# overwrite_dashboards => false,
# configure_telegraf => true,
#enable_telegraf => true,
#master_list => $infranode,
#puppetdb_list => [$pdb],
#postgres_host_list => [$postgres],

#}
#
# this is where lists of master_list , puppetdb_list, postgres_host_list hosts are found using a puppetdb query
#make sure each list is same format

#conditions of whether postgres is present or not

#in the below class

$puppet_severs = rsan::get_puppet_servers()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expose these as parameters instead of just declaring as variables? That way someone should be able to call the class like so and override the defaults if they need to:

class { 'rsan::importer':
  puppet_servers => ['server1.company.com', 'server2.company.com'],
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in this instance, I'd be looking to do something like:

class { 'rsan::importer':
  puppet_servers  => $puppet_servers,
  puppetdb_hosts => $puppetdb_hosts,
  postgres_hosts   => $postgres_hosts,
}

Is that right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's what the user would do when the use RSAN. In order for you to allow them to do that you'll need to allow the rsan::importer class to accept parameters that the user passes i.e.

class rsan::importer (
  String $some_param = "hello",
) {

$puppetdb_hosts = rsan::get_puppetdb_hosts()
$postgres_hosts = rsan::get_postgres_hosts()

class { 'puppet_metrics_dashboard':
add_dashboard_examples => true,
overwrite_dashboards => false,
configure_telegraf => true,
enable_telegraf => true,
master_list => $puppet_servers,
puppetdb_list => $puppetdb_hosts,
postgres_host_list => $postgres_hosts,
}

# master_list , puppetdb_list, postgres_host_list need to be queried from the system programatically

Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "martyewings-rsan",
"version": "0.0.1",
"author": "Martin Ewings",
"summary": "Module to Configure Remote Support Access Node for Puppet Enterprise"
"summary": "Module to Configure Remote Support Access Node for Puppet Enterprise",
"license": "Apache-2.0",
"source": "https://github.com/MartyEwings/RSAN",
"project_page": "https://github.com/MartyEwings/RSAN",
Expand Down