From f5d94f49ec259090e7048680be2838f80f65e73a Mon Sep 17 00:00:00 2001 From: Kevin Cotugno Date: Tue, 7 Feb 2023 21:21:45 -0700 Subject: [PATCH] Add ENV helper --- .local/bin/ansible-become-password | 7 +++++++ .local/bin/ansible-vault-password | 7 +++++++ .local/lib/get-env-var.rb | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100755 .local/bin/ansible-become-password create mode 100755 .local/bin/ansible-vault-password create mode 100644 .local/lib/get-env-var.rb diff --git a/.local/bin/ansible-become-password b/.local/bin/ansible-become-password new file mode 100755 index 0000000..70f2650 --- /dev/null +++ b/.local/bin/ansible-become-password @@ -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" diff --git a/.local/bin/ansible-vault-password b/.local/bin/ansible-vault-password new file mode 100755 index 0000000..692a03c --- /dev/null +++ b/.local/bin/ansible-vault-password @@ -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" diff --git a/.local/lib/get-env-var.rb b/.local/lib/get-env-var.rb new file mode 100644 index 0000000..466daa2 --- /dev/null +++ b/.local/lib/get-env-var.rb @@ -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]