From 71c646fe593d4658df4a9181aaf7cb56b99cd091 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 20 Sep 2017 17:26:22 -0400 Subject: [PATCH] become flags are primary with new configuration the sudo flags are always set and become cannot override, switching to simle 'or' will result in become_flags working. also sudo_flags are deprecated. also changed from YAML null causing a 'None' str fixes #30629 (cherry picked from commit 236d13ac3ac8cfb5dd49dbdcac6497fc160ea019) --- CHANGELOG.md | 1 + lib/ansible/config/base.yml | 4 ++-- lib/ansible/playbook/play_context.py | 14 ++++---------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc9ad704c12..21aae1cf6fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ Ansible Changes By Release * Change configuration of defaults to use standard jinja2 instead of custom eval() for using variables in the default field of config (https://github.com/ansible/ansible/pull/30650) +* Fixed precedence and values for become flags and executable settings diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index 0a92fe737fd..5f3bbe8f5d6 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -495,7 +495,7 @@ DEFAULT_BECOME_EXE: - {key: become_exe, section: privilege_escalation} DEFAULT_BECOME_FLAGS: name: Set 'become' executable options - default: ~ + default: '' description: Flags to pass to the privilege escalation executable. env: [{name: ANSIBLE_BECOME_FLAGS}] ini: @@ -1096,7 +1096,7 @@ DEFAULT_SU_EXE: - {key: su_exe, section: defaults} DEFAULT_SU_FLAGS: name: su flags - default: ~ + default: '' deprecated: why: In favor of become which is a generic framework version: "2.8" diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 42fa67293b6..6d48ed2539e 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -540,19 +540,13 @@ class PlayContext(Base): command = success_cmd # set executable to use for the privilege escalation method, with various overrides - exe = self.become_method - for myexe in (getattr(self, '%s_exe' % self.become_method, None), self.become_exe): - if myexe: - exe = myexe - break + exe = self.become_exe or getattr(self, '%s_exe' % self.become_method, self.become_method) # set flags to use for the privilege escalation method, with various overrides - flags = '' - for myflag in (getattr(self, '%s_flags' % self.become_method, None), self.become_flags): - if myflag is not None: - flags = myflag - break + flags = self.become_flags or getattr(self, '%s_flags' % self.become_method, '') + print(exe) + print(flags) if self.become_method == 'sudo': # If we have a password, we run sudo with a randomly-generated # prompt set using -p. Otherwise we run it with default -n, which makes