From ca060029d39b69fdf174a72f92786b60bb811436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Negr=C3=B3n?= Date: Mon, 9 Dec 2024 13:45:00 +0000 Subject: [PATCH 1/5] Add rb sensor id and role configuration --- resources/providers/config.rb | 41 +++++++++++++++++++ resources/resources/config.rb | 1 + .../templates/default/role-once.json.erb | 9 ++++ resources/templates/default/role.json.erb | 9 ++++ resources/templates/default/variable.erb | 1 + 5 files changed, 61 insertions(+) create mode 100644 resources/templates/default/role-once.json.erb create mode 100644 resources/templates/default/role.json.erb create mode 100644 resources/templates/default/variable.erb diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 712e210..abb66d6 100755 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -5,6 +5,7 @@ # nofile settings hard = new_resource.hard soft = new_resource.soft + sensor_role = new_resource.sensor_role template '/etc/security/limits.d/10-nofile.conf' do source '10-nofile.conf.erb' @@ -16,4 +17,44 @@ variables(soft: soft, hard: hard) end + + if sensor_role + sensor_id = node["redborder"]["sensor_id"] + if sensor_id.nil? + sensor_id = 0 + else + sensor_id = sensor_id.to_i + end + + template '/etc/rb-id' do + source 'variable.erb' + cookbook 'rb-common' + owner 'root' + group 'root' + mode '600' + retries 2 + backup false + variables(variable: sensor_id) + end + + template '/etc/chef/role.json' do + source 'role.json.erb' + cookbook 'rb-common' + owner 'root' + group 'root' + mode '644' + retries 2 + variables(sensor_role: sensor_role, sensor_id: sensor_id) + end + + template '/etc/chef/role-once.json' do + source 'role-once.json.erb' + cookbook 'rb-common' + owner 'root' + group 'root' + mode '644' + retries 2 + variables(sensor_role: sensor_role, sensor_id: sensor_id) + end + end end diff --git a/resources/resources/config.rb b/resources/resources/config.rb index 76faea7..2a53093 100755 --- a/resources/resources/config.rb +++ b/resources/resources/config.rb @@ -6,3 +6,4 @@ attribute :soft, kind_of: Integer, default: 65535 attribute :hard, kind_of: Integer, default: 65535 +attribute :sensor_role, kind_of: String diff --git a/resources/templates/default/role-once.json.erb b/resources/templates/default/role-once.json.erb new file mode 100644 index 0000000..39d139c --- /dev/null +++ b/resources/templates/default/role-once.json.erb @@ -0,0 +1,9 @@ +{ + "run_list": [ + "role[<%= "#{@sensor_role}" %>]", + "role[<%= @sensor_id>0 ? "rBsensor-#{@sensor_id}" : "proxy-sensor" %>]" + ], + "redborder": { + "force-run-once": true + } +} \ No newline at end of file diff --git a/resources/templates/default/role.json.erb b/resources/templates/default/role.json.erb new file mode 100644 index 0000000..85f0926 --- /dev/null +++ b/resources/templates/default/role.json.erb @@ -0,0 +1,9 @@ +{ + "run_list": [ + "role[<%= "#{@sensor_role}" %>]", + "role[<%= @sensor_id>0 ? "rBsensor-#{@sensor_id}" : "proxy-sensor" %>]" + ], + "redborder": { + "force-run-once": false + } +} \ No newline at end of file diff --git a/resources/templates/default/variable.erb b/resources/templates/default/variable.erb new file mode 100644 index 0000000..07195f2 --- /dev/null +++ b/resources/templates/default/variable.erb @@ -0,0 +1 @@ +<%= @variable.nil? ? "" : @variable %> \ No newline at end of file From 771d205eec7cc06674d5c3eebd21a6fa2ab0ffd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Negr=C3=B3n?= Date: Mon, 9 Dec 2024 16:18:41 +0000 Subject: [PATCH 2/5] Bump version --- CHANGELOG.md | 5 +++++ resources/metadata.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5ae40c..a91f5a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ cookbook-rb-common CHANGELOG =============== +## 4.0.0 + + - Miguel Negrón + - [ca06002] Add rb sensor id and role configuration + ## 3.0.1 - Miguel Negrón diff --git a/resources/metadata.rb b/resources/metadata.rb index 95541b3..b711370 100755 --- a/resources/metadata.rb +++ b/resources/metadata.rb @@ -3,4 +3,4 @@ maintainer_email 'git@redborder.com' license 'AGPL-3.0' description 'Redborder common system settings' -version '3.0.1' +version '4.0.0' From a345b80ff33f2dc7f1ea2212f69727e74904184e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Negr=C3=B3n?= Date: Mon, 9 Dec 2024 16:20:12 +0000 Subject: [PATCH 3/5] Fix role references --- resources/templates/default/role-once.json.erb | 2 +- resources/templates/default/role.json.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/templates/default/role-once.json.erb b/resources/templates/default/role-once.json.erb index 39d139c..3d09373 100644 --- a/resources/templates/default/role-once.json.erb +++ b/resources/templates/default/role-once.json.erb @@ -1,7 +1,7 @@ { "run_list": [ "role[<%= "#{@sensor_role}" %>]", - "role[<%= @sensor_id>0 ? "rBsensor-#{@sensor_id}" : "proxy-sensor" %>]" + "role[<%= @sensor_id>0 ? "rBsensor-#{@sensor_id}" : "{@sensor_role}" %>]" ], "redborder": { "force-run-once": true diff --git a/resources/templates/default/role.json.erb b/resources/templates/default/role.json.erb index 85f0926..7ee217a 100644 --- a/resources/templates/default/role.json.erb +++ b/resources/templates/default/role.json.erb @@ -1,7 +1,7 @@ { "run_list": [ "role[<%= "#{@sensor_role}" %>]", - "role[<%= @sensor_id>0 ? "rBsensor-#{@sensor_id}" : "proxy-sensor" %>]" + "role[<%= @sensor_id>0 ? "rBsensor-#{@sensor_id}" : "{@sensor_role}" %>]" ], "redborder": { "force-run-once": false From 0ab00f1aad2ff97d8ee9cb06212a094c220da747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Negr=C3=B3n?= Date: Mon, 9 Dec 2024 16:21:52 +0000 Subject: [PATCH 4/5] Pass lint --- resources/providers/config.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index abb66d6..9a9238c 100755 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -19,13 +19,9 @@ end if sensor_role - sensor_id = node["redborder"]["sensor_id"] - if sensor_id.nil? - sensor_id = 0 - else - sensor_id = sensor_id.to_i - end - + sensor_id = node['redborder']['sensor_id'] + sensor_id = sensor_id.nil? ? 0 : sensor_id.to_i + template '/etc/rb-id' do source 'variable.erb' cookbook 'rb-common' From 68c7afbbacb894f7341b462f775f99364d6dcde5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Negr=C3=B3n?= Date: Mon, 9 Dec 2024 16:23:35 +0000 Subject: [PATCH 5/5] Pass lint --- resources/providers/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 9a9238c..0bf32e7 100755 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -42,7 +42,7 @@ retries 2 variables(sensor_role: sensor_role, sensor_id: sensor_id) end - + template '/etc/chef/role-once.json' do source 'role-once.json.erb' cookbook 'rb-common'