From 620accf117f4cae718ec4bba626150a7580f5f68 Mon Sep 17 00:00:00 2001 From: Jonathan Palley Date: Wed, 26 Sep 2012 02:57:00 +0800 Subject: [PATCH 1/2] make delegate_to localhost act like local_action --- lib/ansible/playbook/task.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 69f62f4796f..18a77afa7e1 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -62,6 +62,11 @@ class Task(object): self.action = ds.get('local_action', '') self.delegate_to = '127.0.0.1' self.transport = 'local' + # delegate_to: localhost should use local transport + elif (ds.get('delegate_to', None) in ['127.0.0.1', 'localhost']): + self.action = ds.get('action', '') + self.delegate_to = '127.0.0.1' + self.transport = 'local' else: self.action = ds.get('action', '') self.delegate_to = ds.get('delegate_to', None) From faed650bb13c9e0ec53231ca483fff7be97530cd Mon Sep 17 00:00:00 2001 From: Jonathan Palley Date: Wed, 26 Sep 2012 03:47:17 +0800 Subject: [PATCH 2/2] allow vars in delegate_to --- lib/ansible/playbook/task.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 18a77afa7e1..5003fbf4337 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -50,7 +50,7 @@ class Task(object): self.name = ds.get('name', None) self.tags = [ 'all' ] self.register = ds.get('register', None) - + # Both are defined if ('action' in ds) and ('local_action' in ds): raise errors.AnsibleError("the 'action' and 'local_action' attributes can not be used together") @@ -61,17 +61,18 @@ class Task(object): elif 'local_action' in ds: self.action = ds.get('local_action', '') self.delegate_to = '127.0.0.1' - self.transport = 'local' - # delegate_to: localhost should use local transport - elif (ds.get('delegate_to', None) in ['127.0.0.1', 'localhost']): - self.action = ds.get('action', '') - self.delegate_to = '127.0.0.1' - self.transport = 'local' else: self.action = ds.get('action', '') self.delegate_to = ds.get('delegate_to', None) self.transport = ds.get('transport', play.transport) + # delegate_to can use variables + if not (self.delegate_to is None): + self.delegate_to = utils.template(None, self.delegate_to, self.module_vars) + # delegate_to: localhost should use local transport + if self.delegate_to in ['127.0.0.1', 'localhost']: + self.transport = 'local' + # notified by is used by Playbook code to flag which hosts # need to run a notifier self.notified_by = []