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' diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 712e210..0bf32e7 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,40 @@ variables(soft: soft, hard: hard) end + + if sensor_role + 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' + 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..3d09373 --- /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}" : "{@sensor_role}" %>]" + ], + "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..7ee217a --- /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}" : "{@sensor_role}" %>]" + ], + "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