issue #499: respect C.BECOME_ALLOW_SAME_USER.
This commit is contained in:
parent
16a2de65c4
commit
a1121c5a84
|
@ -587,7 +587,8 @@ class Connection(ansible.plugins.connection.ConnectionBase):
|
|||
)
|
||||
|
||||
stack += (CONNECTION_METHOD[spec.transport()](spec),)
|
||||
if spec.become():
|
||||
if spec.become() and ((spec.become_user() != spec.remote_user()) or
|
||||
C.BECOME_ALLOW_SAME_USER):
|
||||
stack += (CONNECTION_METHOD[spec.become_method()](spec),)
|
||||
|
||||
return stack
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
# become_same_user.yml
|
||||
bsu-joe ansible_user=joe
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
---
|
||||
|
||||
- include: become_same_user.yml
|
||||
- include: disconnect_during_module.yml
|
||||
- include: disconnect_resets_connection.yml
|
||||
- include: exec_command.yml
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# issue #499: ensure C.BECOME_ALLOW_SAME_USER is respected.
|
||||
---
|
||||
|
||||
- name: integration/connection/become_same_user.yml
|
||||
hosts: bsu-joe
|
||||
gather_facts: no
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
|
||||
# bsu-joe's login user is joe, so become should be ignored.
|
||||
- mitogen_get_stack:
|
||||
become: true
|
||||
become_user: joe
|
||||
register: out
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- out.result[0].method == "ssh"
|
||||
- out.result[0].kwargs.username == "joe"
|
||||
- out.result|length == 1 # no sudo
|
||||
|
||||
|
||||
# Now try with a different account.
|
||||
- mitogen_get_stack:
|
||||
become: true
|
||||
become_user: james
|
||||
register: out
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- out.result[0].method == "ssh"
|
||||
- out.result[0].kwargs.username == "joe"
|
||||
- out.result[1].method == "sudo"
|
||||
- out.result[1].kwargs.username == "james"
|
||||
- out.result|length == 2 # no sudo
|
Loading…
Reference in New Issue