Skip to content
Permalink
Browse files

tests/ansible: Spec.become_method() test & mitogen_via= fix.

ansible_become_method hostvar was not taken into account.
  • Loading branch information...
dw committed Feb 12, 2019
1 parent 4d33598 commit 8ae6ca1d5b83de17a83e943aa4028ed2f8f30bdd
@@ -486,7 +486,11 @@ def become(self):
return bool(self._become_user)

def become_method(self):
return self._become_method or C.DEFAULT_BECOME_METHOD
return (
self._become_method or
self._host_vars.get('ansible_become_method') or
C.DEFAULT_BECOME_METHOD
)

def become_user(self):
return self._become_user
@@ -143,8 +143,8 @@ Fixes
``ansible_ssh_host`` parameter is respected when ``mitogen_via=`` is active.

* `21ad299d <https://github.com/dw/mitogen/commit/21ad299d>`_: the
precedence of ``ansible_ssh_user`` and ``ansible_user`` was corrected when
when ``mitogen_via=`` is active.
precedence of ``ansible_ssh_user`` and ``ansible_user`` was corrected when
when ``mitogen_via=`` is active.


Thanks!
@@ -27,3 +27,7 @@ tc-password-explicit-both ansible_password=a.b.c ansible_ssh_pass=c.b.a
# become()
tc-become-unset
tc-become-set

# become_method()
tc-become-method-unset
tc-become-method-su ansible_become_method=su
@@ -1,4 +1,5 @@
- include: become.yml
- include: become_method.yml
- include: password.yml
- include: python_path.yml
- include: remote_addr.yml
@@ -0,0 +1,83 @@
# Each case is followed by mitogen_via= case to test hostvars method.


# No become-method set.
- name: integration/transport_config/become-method.yml
hosts: tc-become-method-unset
become: true
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert:
that:
- out.result|length == 2
- out.result[0].method == "ssh"
- out.result[1].method == "sudo"

- hosts: tc-become-method-unset
vars: {mitogen_via: becomeuser@tc-become-method-su}
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert:
that:
- out.result|length == 3
- out.result[0].method == "ssh"
- out.result[1].method == "su"
- out.result[1].kwargs.username == "becomeuser"
- out.result[2].method == "ssh"
- out.result[2].kwargs.hostname == "tc-become-method-unset"


# ansible_become_method=su
- hosts: tc-become-method-su
become: true
become_user: becomeuser
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert:
that:
- out.result|length == 2
- out.result[0].method == "ssh"
- out.result[1].method == "su"
- out.result[1].kwargs.username == "becomeuser"

- hosts: tc-become-method-su
vars: {mitogen_via: tc-become-method-unset}
become: true
become_user: becomeuser
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert:
that:
- out.result|length == 3
- out.result[0].method == "ssh"
- out.result[0].kwargs.hostname == "tc-become-method-unset"

- out.result[1].method == "ssh"
- out.result[1].kwargs.hostname == "tc-become-method-su"

- out.result[2].method == "su"
- out.result[2].kwargs.username == "becomeuser"



# mitogen_via used to specify explicit become method
- hosts: tc-become-method-unset
vars: {mitogen_via: "doas:doasuser@tc-become-method-su"}
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert:
that:
- out.result|length == 3
- out.result[0].method == "ssh"
- out.result[0].kwargs.hostname == "tc-become-method-su"

- out.result[1].method == "doas"
- out.result[1].kwargs.username == "doasuser"

- out.result[2].method == "ssh"
- out.result[2].kwargs.hostname == "tc-become-method-unset"

0 comments on commit 8ae6ca1

Please sign in to comment.
You can’t perform that action at this time.