Skip to content

configure classifier data in global hiera.yaml #44

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

Merged
merged 2 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions plans/action/configure.pp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# @summary Configure first-time classification and HA setup
#
plan peadm::action::configure (
# Large
# Standard
Peadm::SingleTargetSpec $master_host,
Optional[TargetSpec] $compiler_hosts = undef,
Optional[Peadm::SingleTargetSpec] $master_replica_host = undef,

# Large
Optional[TargetSpec] $compiler_hosts = undef,

# Extra Large
Optional[Peadm::SingleTargetSpec] $puppetdb_database_host = undef,
Optional[Peadm::SingleTargetSpec] $puppetdb_database_replica_host = undef,
Expand Down Expand Up @@ -37,8 +39,25 @@
$compiler_hosts,
)

# Set up the console node groups to configure the various hosts in their
# roles
# Define the global hiera.yaml file on the Master; and syncronize to any Replica and Compilers.
# This enables Data in the Classifier/Console, which is used/required by this architecture.
# Necessary, for example, when promoting the Replica due to PE-18400 (and others).
$global_hiera_yaml = run_task('peadm::read_file', $master_target,
path => '/etc/puppetlabs/puppet/hiera.yaml',
).first['content']

run_task('peadm::mkdir_p_file', peadm::flatten_compact([
$master_replica_target,
$compiler_targets,
)],
path => '/etc/puppetlabs/puppet/hiera.yaml',
owner => 'root',
group => 'root',
mode => '0644',
content => $global_hiera_yaml,
)

# Set up the console node groups to configure the various hosts in their roles

# Pending resolution of Bolt GH-1244, Target objects and their methods are
# not accessible inside apply() blocks. Work around the limitation for now
Expand Down
10 changes: 10 additions & 0 deletions tasks/read_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "Read the contents of a file",
"parameters": {
"path": {
"type": "String",
"description": "Path to the file to read"
}
},
"input_method": "environment"
}
18 changes: 18 additions & 0 deletions tasks/read_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

main() {
cat "$PT_path"
}

outfile=$(mktemp)
main "$@" >"$outfile" 2>&1
exit_code=$?

cat <<EOS
{
"content": $(python -c "import json; print json.dumps(open('$outfile','r').read())")
Copy link
Contributor

Choose a reason for hiding this comment

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

fwiw, python isn't available by default on rhel 8... I'm actually confused what was wrong with actually using cat here.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's good to know. Hmm.

Python is needed/used because the result returned needs to be JSON, and special characters like newlines need to be JSON encoded to be returned.

Looks like python isn't available by default on Ubuntu 18.04 either.

I think the workaround for now is gonna have to be shipping a Ruby implementation of this task. At the moment we only use it after Puppet is installed, so that should work ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW /usr/bin/python3 is installed on my Platform9 Ubuntu VMs.
Yes, ruby ...

}
EOS

rm "$outfile"
exit $exit_code