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

ansible_become_method hostvar was not taken into account.
pull/564/head
David Wilson 6 years ago
parent 4d33598fa0
commit 8ae6ca1d5b

@ -486,7 +486,11 @@ class MitogenViaSpec(Spec):
return bool(self._become_user) return bool(self._become_user)
def become_method(self): 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): def become_user(self):
return self._become_user return self._become_user

@ -143,8 +143,8 @@ Fixes
``ansible_ssh_host`` parameter is respected when ``mitogen_via=`` is active. ``ansible_ssh_host`` parameter is respected when ``mitogen_via=`` is active.
* `21ad299d <https://github.com/dw/mitogen/commit/21ad299d>`_: the * `21ad299d <https://github.com/dw/mitogen/commit/21ad299d>`_: the
precedence of ``ansible_ssh_user`` and ``ansible_user`` was corrected when precedence of ``ansible_ssh_user`` and ``ansible_user`` was corrected when
when ``mitogen_via=`` is active. when ``mitogen_via=`` is active.
Thanks! Thanks!

@ -27,3 +27,7 @@ tc-password-explicit-both ansible_password=a.b.c ansible_ssh_pass=c.b.a
# become() # become()
tc-become-unset tc-become-unset
tc-become-set 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.yml
- include: become_method.yml
- include: password.yml - include: password.yml
- include: python_path.yml - include: python_path.yml
- include: remote_addr.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"
Loading…
Cancel
Save