From de5eae2007d4138730582e876770d3b24c863753 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 11 Mar 2015 12:18:53 -0400 Subject: [PATCH] fixed traceback when x_user implicitly sets the become method Fixes #10430 Also removed redundant resolution of sudo/su for backwards compatibility which confused the conflict detection code. --- lib/ansible/playbook/play.py | 23 ----------------------- lib/ansible/playbook/task.py | 21 ++++++++++++++++++--- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 74c6998b22f..babc059e65f 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -583,29 +583,6 @@ class Play(object): included_become_vars[k] = become_vars[k] x[k] = become_vars[k] - ## backwards compat with old sudo/su directives - if 'sudo' in x or 'sudo_user' in x: - included_become_vars['become'] = x['sudo'] - x['become'] = x['sudo'] - x['become_method'] = 'sudo' - del x['sudo'] - - if x.get('sudo_user', False): - included_become_vars['become_user'] = x['sudo_user'] - x['become_user'] = x['sudo_user'] - del x['sudo_user'] - - elif 'su' in x or 'su_user' in x: - included_become_vars['become'] = x['su'] - x['become'] = x['su'] - x['become_method'] = 'su' - del x['su'] - - if x.get('su_user', False): - included_become_vars['become_user'] = x['su_user'] - x['become_user'] = x['su_user'] - del x['su_user'] - if 'meta' in x: if x['meta'] == 'flush_handlers': results.append(Task(self, x)) diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index a43c2ab89d5..77cb97e5c0f 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -173,19 +173,34 @@ class Task(object): # set only if passed in current task data if 'sudo' in ds or 'sudo_user' in ds: - self.become=ds['sudo'] self.become_method='sudo' + + if 'sudo' in ds: + self.become=ds['sudo'] + del ds['sudo'] + else: + self.become=True if 'sudo_user' in ds: self.become_user = ds['sudo_user'] + del ds['sudo_user'] if 'sudo_pass' in ds: self.become_pass = ds['sudo_pass'] - if 'su' in ds or 'su_user' in ds: - self.become=ds['su'] + del ds['sudo_pass'] + + elif 'su' in ds or 'su_user' in ds: self.become_method='su' + + if 'su' in ds: + self.become=ds['su'] + else: + self.become=True + del ds['su'] if 'su_user' in ds: self.become_user = ds['su_user'] + del ds['su_user'] if 'su_pass' in ds: self.become_pass = ds['su_pass'] + del ds['su_pass'] # Both are defined if ('action' in ds) and ('local_action' in ds):