Add ENV helper

This commit is contained in:
Kevin Cotugno 2023-02-07 21:21:45 -07:00
parent dec408e377
commit f5d94f49ec
3 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# vim:ft=ruby
@var_name = "ANSIBLE_BECOME_PASSWORD"
require_relative "../lib/get-env-var"

View File

@ -0,0 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# vim:ft=ruby
@var_name = "ANSIBLE_VAULT_PASSWORD"
require_relative "../lib/get-env-var"

13
.local/lib/get-env-var.rb Normal file
View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
if !defined?(@var_name)
$stderr.puts "`var_name` is undefined"
exit 2
end
if !ENV.key?(@var_name)
$stderr.puts "#{@var_name} is not set"
exit 1
end
printf "%s", ENV[@var_name]