From abe126fbd8ca13a15fc5a1303f9dc0d88c436881 Mon Sep 17 00:00:00 2001 From: Stoned Elipot Date: Fri, 15 Mar 2013 21:42:55 +0100 Subject: [PATCH 1/2] Define, when possible, the inventory_dir variable --- docsite/rst/playbooks2.rst | 2 ++ lib/ansible/playbook/__init__.py | 7 +++++-- lib/ansible/playbook/play.py | 7 +++++-- lib/ansible/runner/__init__.py | 2 ++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docsite/rst/playbooks2.rst b/docsite/rst/playbooks2.rst index a47fdc58e9f..c251734a09e 100644 --- a/docsite/rst/playbooks2.rst +++ b/docsite/rst/playbooks2.rst @@ -141,6 +141,8 @@ period, without the rest of the domain. Don't worry about any of this unless you think you need it. You'll know when you do. +Also available, *inventory_dir* is the pathname of the directory holding Ansible's inventory host file. + Variable File Separation ```````````````````````` diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 91e1aa39bc8..4d561f30093 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -121,7 +121,10 @@ class PlayBook(object): self.inventory = inventory self.basedir = os.path.dirname(playbook) or '.' - (self.playbook, self.play_basedirs) = self._load_playbook_from_file(playbook) + vars = {} + if self.inventory.basedir() is not None: + vars['inventory_dir'] = self.inventory.basedir() + (self.playbook, self.play_basedirs) = self._load_playbook_from_file(playbook, vars) # ***************************************************** @@ -171,7 +174,7 @@ class PlayBook(object): for t in tokens[1:]: (k,v) = t.split("=", 1) incvars[k] = utils.template(basedir, v, incvars) - included_path = utils.path_dwim(basedir, tokens[0]) + included_path = utils.path_dwim(basedir, utils.template(basedir, tokens[0], incvars)) (plays, basedirs) = self._load_playbook_from_file(included_path, incvars) for p in plays: if 'vars' not in p: diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 67e1c1a2173..e59912c458c 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -80,8 +80,11 @@ class Play(object): self._update_vars_files_for_host(None) - self._tasks = self._load_tasks(self._ds.get('tasks', [])) - self._handlers = self._load_tasks(self._ds.get('handlers', [])) + load_vars = {} + if self.playbook.inventory.basedir() is not None: + load_vars['inventory_dir'] = self.playbook.inventory.basedir(); + self._tasks = self._load_tasks(self._ds.get('tasks', []), load_vars) + self._handlers = self._load_tasks(self._ds.get('handlers', []), load_vars) if self.tags is None: self.tags = [] diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index f0826c3bdd3..c0b5e9c9c5b 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -337,6 +337,8 @@ class Runner(object): inject['hostvars'] = HostVars(self.setup_cache, self.inventory) inject['group_names'] = host_variables.get('group_names', []) inject['groups'] = self.inventory.groups_list() + if self.inventory.basedir() is not None: + inject['inventory_dir'] = self.inventory.basedir() # allow with_foo to work in playbooks... items = None From 774bf8abe6b299c3b015c0998913d823431f2e2a Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 25 Mar 2013 22:24:30 -0400 Subject: [PATCH 2/2] Add state to rhn_channel docs --- library/rhn_channel | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/rhn_channel b/library/rhn_channel index 695aee713e8..1d45f978b50 100755 --- a/library/rhn_channel +++ b/library/rhn_channel @@ -23,6 +23,11 @@ options: - name of the system as it is known in RHN/Satellite required: true default: null + state: + description: + - whether the channel should be present or not + required: false + default: present url: description: - The full url to the RHN/Satellite api