Skip to content

Commit 31d770e

Browse files
Add node attributes json generation
The function will export all the node attribute to a json file at the beginning of the install phase. Doing so other scripts can read the file instead of point directly to the default.rb Signed-off-by: Francesco Giordano <[email protected]>
1 parent 3daaf15 commit 31d770e

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

cookbooks/aws-parallelcluster-install/recipes/install.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
return if node['conditions']['ami_bootstrapped']
2222

23+
node_attributes 'Generate export in json at /etc/chef/node_attributes.json'
24+
2325
include_recipe 'aws-parallelcluster-install::base'
2426
include_recipe "aws-parallelcluster-install::clusterstatusmgtd"
2527
include_recipe "aws-parallelcluster-install::intel"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright:: 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License").
6+
# You may not use this file except in compliance with the License.
7+
# A copy of the License is located at
8+
#
9+
# http://aws.amazon.com/apache2.0/
10+
#
11+
# or in the "LICENSE.txt" file accompanying this file.
12+
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
13+
# See the License for the specific language governing permissions and limitations under the License.
14+
15+
provides :node_attributes
16+
unified_mode true
17+
default_action :generate_json
18+
19+
action :generate_json do
20+
json_content = Chef::JSONCompat.to_json_pretty(node)
21+
file "/etc/chef/node_attributes.json" do
22+
content "#{json_content}"
23+
owner 'root'
24+
mode '0644'
25+
end
26+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
control 'node_attributes' do
2+
title 'Test the generation of the node attributes json file'
3+
4+
describe file('/etc/chef/node_attributes.json') do
5+
it { should exist }
6+
its('content') { should match(/^ "cluster": \{$/) }
7+
# its('content_as_json') { should include('cluster') }
8+
# its('content_as_json') { should include('cluster' => { 'base_dir' => '/opt/parallelcluster' }) }
9+
end
10+
end

0 commit comments

Comments
 (0)