summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorjamiesonio <j@colburn.io>2018-09-20 00:19:35 +0200
committeransibot <ansibot@users.noreply.github.com>2018-09-20 00:19:35 +0200
commit6711c9524e1bcf147a85fc71a62192aa75410955 (patch)
treed04bea6b3c299e2ed04c4d8ee6623c8b870f464a /contrib
parentFixing but on version check when the "Apache/2.4.x (Distro)" regex is not met... (diff)
downloadansible-6711c9524e1bcf147a85fc71a62192aa75410955.tar.xz
ansible-6711c9524e1bcf147a85fc71a62192aa75410955.zip
Add environmental variables to allow for the script to be run without consul_io.ini. This allows it to run dynamically without any prerequisite config file (#30900)
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/inventory/consul_io.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/contrib/inventory/consul_io.py b/contrib/inventory/consul_io.py
index 17defb435e..b4bf022bdb 100755
--- a/contrib/inventory/consul_io.py
+++ b/contrib/inventory/consul_io.py
@@ -49,12 +49,14 @@ Other options include:
'datacenter':
which restricts the included nodes to those from the given datacenter
+This can also be set with the environmental variable CONSUL_DATACENTER
'url':
the URL of the Consul cluster. host, port and scheme are derived from the
URL. If not specified, connection configuration defaults to http requests
to localhost on port 8500.
+This can also be set with the environmental variable CONSUL_URL
'domain':
@@ -453,6 +455,7 @@ class ConsulConfig(dict):
def __init__(self):
self.read_settings()
self.read_cli_args()
+ self.read_env_vars()
def has_config(self, name):
if hasattr(self, name):
@@ -497,6 +500,14 @@ class ConsulConfig(dict):
if getattr(args, arg):
setattr(self, arg, getattr(args, arg))
+ def read_env_vars(self):
+ env_var_options = ['datacenter', 'url']
+ for option in env_var_options:
+ value = None
+ env_var = 'CONSUL_' + option.upper()
+ if os.environ.get(env_var):
+ setattr(self, option, os.environ.get(env_var))
+
def get_availability_suffix(self, suffix, default):
if self.has_config(suffix):
return self.has_config(suffix)