Browse code

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)

Brian Coca authored on 2017/09/21 06:26:22
Showing 3 changed files
... ...
@@ -31,6 +31,7 @@ Ansible Changes By Release
31 31
 * Change configuration of defaults to use standard jinja2 instead of custom
32 32
   eval() for using variables in the default field of config (https://github.com/ansible/ansible/pull/30650)
33 33
 
34
+* Fixed precedence and values for become flags and executable settings
34 35
 
35 36
 <a id="2.4"></a>
36 37
 
... ...
@@ -495,7 +495,7 @@ DEFAULT_BECOME_EXE:
495 495
   - {key: become_exe, section: privilege_escalation}
496 496
 DEFAULT_BECOME_FLAGS:
497 497
   name: Set 'become' executable options
498
-  default: ~
498
+  default: ''
499 499
   description: Flags to pass to the privilege escalation executable.
500 500
   env: [{name: ANSIBLE_BECOME_FLAGS}]
501 501
   ini:
... ...
@@ -1096,7 +1096,7 @@ DEFAULT_SU_EXE:
1096 1096
   - {key: su_exe, section: defaults}
1097 1097
 DEFAULT_SU_FLAGS:
1098 1098
   name: su flags
1099
-  default: ~
1099
+  default: ''
1100 1100
   deprecated:
1101 1101
     why: In favor of become which is a generic framework
1102 1102
     version: "2.8"
... ...
@@ -540,19 +540,13 @@ class PlayContext(Base):
540 540
                 command = success_cmd
541 541
 
542 542
             # set executable to use for the privilege escalation method, with various overrides
543
-            exe = self.become_method
544
-            for myexe in (getattr(self, '%s_exe' % self.become_method, None), self.become_exe):
545
-                if myexe:
546
-                    exe = myexe
547
-                    break
543
+            exe = self.become_exe or getattr(self, '%s_exe' % self.become_method, self.become_method)
548 544
 
549 545
             # set flags to use for the privilege escalation method, with various overrides
550
-            flags = ''
551
-            for myflag in (getattr(self, '%s_flags' % self.become_method, None), self.become_flags):
552
-                if myflag is not None:
553
-                    flags = myflag
554
-                    break
546
+            flags = self.become_flags or getattr(self, '%s_flags' % self.become_method, '')
555 547
 
548
+            print(exe)
549
+            print(flags)
556 550
             if self.become_method == 'sudo':
557 551
                 # If we have a password, we run sudo with a randomly-generated
558 552
                 # prompt set using -p. Otherwise we run it with default -n, which makes