From 74402b4c03f1e0019e9f1befae7ee449b8322741 Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Wed, 17 May 2017 11:06:37 +0200 Subject: [PATCH] eypconf facts --- CHANGELOG.md | 3 +++ lib/facter/eypconf_env.rb | 26 ++++++++++++++++++++++++++ lib/facter/eypconf_magic_hash.rb | 9 +++++++++ lib/facter/eypconf_type.rb | 25 +++++++++++++++++++++++++ lib/facter/eypconf_userid.rb | 21 +++++++++++++++++++++ metadata.json | 2 +- 6 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 lib/facter/eypconf_env.rb create mode 100644 lib/facter/eypconf_magic_hash.rb create mode 100644 lib/facter/eypconf_type.rb create mode 100644 lib/facter/eypconf_userid.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 4591f22..41e0f65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,5 @@ # CHANGELOG +## 0.1.8 + +* added **eypconf** facts diff --git a/lib/facter/eypconf_env.rb b/lib/facter/eypconf_env.rb new file mode 100644 index 0000000..318365c --- /dev/null +++ b/lib/facter/eypconf_env.rb @@ -0,0 +1,26 @@ +if File.exists?('/opt/eypconf/id/env.sh') then + env = Facter::Util::Resolution.exec('bash /opt/eypconf/id/env.sh').to_s +else + env = Facter::Util::Resolution.exec('bash -c \'if [ -f /opt/eypconf/id/env ]; then cat /opt/eypconf/id/env | paste -sd,; fi\'').to_s +end + +unless env.nil? or env.empty? + Facter.add('eypconf_env') do + setcode do + env + end + end + + Facter.add('eypconf_env_uppercase') do + setcode do + env.upcase + end + end + + Facter.add('eypconf_env_lowercase') do + setcode do + env.downcase + end + end + +end diff --git a/lib/facter/eypconf_magic_hash.rb b/lib/facter/eypconf_magic_hash.rb new file mode 100644 index 0000000..8377f60 --- /dev/null +++ b/lib/facter/eypconf_magic_hash.rb @@ -0,0 +1,9 @@ +magichash = Facter::Util::Resolution.exec('bash -c \'if [ -f /opt/eypconf/id/.magic ]; then cat /opt/eypconf/id/.magic | paste -sd,; else echo "deadbeef"; fi\'').to_s + +unless magichash.nil? or magichash.empty? + Facter.add('eypconf_magic_hash') do + setcode do + magichash + end + end +end diff --git a/lib/facter/eypconf_type.rb b/lib/facter/eypconf_type.rb new file mode 100644 index 0000000..a25997f --- /dev/null +++ b/lib/facter/eypconf_type.rb @@ -0,0 +1,25 @@ +if File.exists?('/opt/eypconf/id/type.sh') then + nodetype = Facter::Util::Resolution.exec('bash /opt/eypconf/id/type.sh').to_s +else + nodetype = Facter::Util::Resolution.exec('bash -c \'if [ -f /opt/eypconf/id/type ]; then cat /opt/eypconf/id/type | paste -sd,; fi\'') +end + +unless nodetype.nil? or nodetype.empty? + Facter.add('eypconf_type') do + setcode do + nodetype + end + end + + Facter.add('eypconf_type_uppercase') do + setcode do + nodetype.upcase + end + end + + Facter.add('eypconf_type_lowercase') do + setcode do + nodetype.downcase + end + end +end diff --git a/lib/facter/eypconf_userid.rb b/lib/facter/eypconf_userid.rb new file mode 100644 index 0000000..c884896 --- /dev/null +++ b/lib/facter/eypconf_userid.rb @@ -0,0 +1,21 @@ +userid = Facter::Util::Resolution.exec('bash -c \'if [ -f /opt/eypconf/id/customer ]; then cat /opt/eypconf/id/customer | paste -sd,; else echo "defaultcustomer"; fi\'').to_s + +unless userid.nil? or userid.empty? + Facter.add('eypconf_userid') do + setcode do + userid + end + end + + Facter.add('eypconf_userid_uppercase') do + setcode do + userid.upcase + end + end + + Facter.add('eypconf_userid_lowercase') do + setcode do + userid.downcase + end + end +end diff --git a/metadata.json b/metadata.json index c62f9c9..92c014d 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "eyp-eyplib", - "version": "0.1.7", + "version": "0.1.8", "author": "eyp", "summary": "Utility functions for puppet modules", "license": "Apache-2.0",