aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-04-14 08:47:27 +0200
committerGuido Günther <agx@sigxcpu.org>2016-04-14 08:47:27 +0200
commit4cb6d186a27a86da6dd20796e1c1efc6673e0dbf (patch)
tree19fb930ab0e48c7262f16df09d45bcae48437692
parent085db1429da054c5c7f7e26a7b3fbbbce1a358f7 (diff)
parent54339737800fec0197e309c82f38320825510555 (diff)
Merge pull request #11 from wwitzel3/master
read foreman.ini from environment if set
-rw-r--r--README.md8
-rwxr-xr-xforeman_ansible_inventory.py13
2 files changed, 16 insertions, 5 deletions
diff --git a/README.md b/README.md
index 780d48d..fd1d241 100644
--- a/README.md
+++ b/README.md
@@ -3,8 +3,12 @@ foreman_ansible_inventory
This script can be used as an ansible dynamic inventory[1].
The connection parameters are set up via a configuration
-file *foreman.ini* that resides in the same directory as the inventory
-script.
+file *foreman.ini*. *foreman.ini* is found using the following
+order of discovery.
+
+ * `/etc/ansible/foreman.ini`
+ * Current directory of your inventory script.
+ * `FOREMAN_INI_PATH` environment variable.
## Variables and Parameters
diff --git a/foreman_ansible_inventory.py b/foreman_ansible_inventory.py
index e2a53c3..bece7c7 100755
--- a/foreman_ansible_inventory.py
+++ b/foreman_ansible_inventory.py
@@ -87,9 +87,16 @@ class ForemanInventory(object):
""" Reads the settings from the foreman.ini file """
config = ConfigParser.SafeConfigParser()
- config.read(
- ["/etc/ansible/foreman.ini",
- os.path.dirname(os.path.realpath(__file__)) + '/foreman.ini'])
+ config_paths = [
+ "/etc/ansible/foreman.ini",
+ os.path.dirname(os.path.realpath(__file__)) + '/foreman.ini',
+ ]
+
+ env_value = os.environ.get('FOREMAN_INI_PATH')
+ if env_value is not None:
+ config_paths.append(os.path.expanduser(os.path.expandvars(env_value)))
+
+ config.read(config_paths)
# Foreman API related
self.foreman_url = config.get('foreman', 'url')