From f649777072e4093125a9548e3d7dbbd9afdd0e69 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Wed, 30 Jan 2013 11:56:04 -0500 Subject: [PATCH 1/2] - make extra-vars override all other vars and facts in playbooks --- lib/ansible/playbook/__init__.py | 4 +++- lib/ansible/playbook/play.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index c572e55fdc..88c35aca5b 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -315,6 +315,8 @@ class PlayBook(object): continue facts = result.get('ansible_facts', {}) self.SETUP_CACHE[host].update(facts) + # extra vars need to always trump - so update again following the facts + self.SETUP_CACHE[host].update(self.extra_vars) if task.register: if 'stdout' in result: result['stdout_lines'] = result['stdout'].splitlines() @@ -390,7 +392,7 @@ class PlayBook(object): ''' run a list of tasks for a given pattern, in order ''' self.callbacks.on_play_start(play.name) - + self.SETUP_CACHE.update(play.vars) # if no hosts matches this play, drop out if not self.inventory.list_hosts(play.hosts): self.callbacks.on_no_hosts_matched() diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index f414ec5553..95d3932394 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -186,6 +186,9 @@ class Play(object): else: vars.update(self.vars) + if type(self.playbook.extra_vars) == dict: + vars.update(self.playbook.extra_vars) + if type(self.vars_prompt) == list: for var in self.vars_prompt: if not 'name' in var: From 83b9654c6386fd5e5efb5793e351a462d0325a81 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Thu, 31 Jan 2013 11:24:22 -0500 Subject: [PATCH 2/2] stop updating SETUP_CACHE in run_play as per comment on pr 1945 --- lib/ansible/playbook/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 88c35aca5b..2fa5fb4845 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -392,7 +392,6 @@ class PlayBook(object): ''' run a list of tasks for a given pattern, in order ''' self.callbacks.on_play_start(play.name) - self.SETUP_CACHE.update(play.vars) # if no hosts matches this play, drop out if not self.inventory.list_hosts(play.hosts): self.callbacks.on_no_hosts_matched()