From e8272e365dc48d0bca4419f583803dc4d22c3e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Sat, 10 Aug 2013 12:59:17 +0200 Subject: [PATCH] implemented 'inventory_file' variable. Closes GH-3789. --- lib/ansible/inventory/__init__.py | 6 ++++++ lib/ansible/playbook/__init__.py | 4 ++++ lib/ansible/runner/__init__.py | 3 +++ 3 files changed, 13 insertions(+) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index d6384247b63..1661fbef22c 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -397,6 +397,12 @@ class Inventory(object): return cwd return dname + def src(self): + """ if inventory came from a file, what's the directory and file name? """ + if not self.is_file(): + return None + return self.host_list + def playbook_basedir(self): """ returns the directory of the current playbook """ return self._playbook_basedir diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 15ac998fd17..6bb09213454 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -140,6 +140,10 @@ class PlayBook(object): vars = extra_vars.copy() if self.inventory.basedir() is not None: vars['inventory_dir'] = self.inventory.basedir() + + if self.inventory.src() is not None: + vars['inventory_file'] = self.inventory.src() + self.filename = playbook (self.playbook, self.play_basedirs) = self._load_playbook_from_file(playbook, vars) ansible.callbacks.load_callback_plugins() diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 277cada1277..30b342fdd76 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -410,6 +410,9 @@ class Runner(object): if self.inventory.basedir() is not None: inject['inventory_dir'] = self.inventory.basedir() + if self.inventory.src() is not None: + inject['inventory_file'] = self.inventory.src() + # late processing of parameterized sudo_user if self.sudo_user is not None: self.sudo_user = template.template(self.basedir, self.sudo_user, inject)