diff --git a/ansible_mitogen/transport_config.py b/ansible_mitogen/transport_config.py index edc9ce1e..3f827744 100644 --- a/ansible_mitogen/transport_config.py +++ b/ansible_mitogen/transport_config.py @@ -497,7 +497,6 @@ class MitogenViaSpec(Spec): def become_pass(self): return optional_secret( - # TODO: Might have to come from PlayContext. self._host_vars.get('ansible_become_password') or self._host_vars.get('ansible_become_pass') ) diff --git a/tests/ansible/hosts/transport_config.hosts b/tests/ansible/hosts/transport_config.hosts index 76998e26..709d26f7 100644 --- a/tests/ansible/hosts/transport_config.hosts +++ b/tests/ansible/hosts/transport_config.hosts @@ -35,3 +35,9 @@ tc-become-method-su ansible_become_method=su # become_user() tc-become-user-unset tc-become-user-set ansible_become_user=ansi-become-user + +# become_pass() +tc-become-pass-unset +tc-become-pass-password ansible_become_password=apassword +tc-become-pass-pass ansible_become_pass=apass +tc-become-pass-both ansible_become_password=a.b.c ansible_become_pass=c.b.a diff --git a/tests/ansible/integration/transport_config/all.yml b/tests/ansible/integration/transport_config/all.yml index 47409b19..23423a9d 100644 --- a/tests/ansible/integration/transport_config/all.yml +++ b/tests/ansible/integration/transport_config/all.yml @@ -1,6 +1,7 @@ -- include: become.yml - include: become_method.yml +- include: become_pass.yml - include: become_user.yml +- include: become.yml - include: password.yml - include: python_path.yml - include: remote_addr.yml diff --git a/tests/ansible/integration/transport_config/become_pass.yml b/tests/ansible/integration/transport_config/become_pass.yml new file mode 100644 index 00000000..02c6528d --- /dev/null +++ b/tests/ansible/integration/transport_config/become_pass.yml @@ -0,0 +1,142 @@ +# Each case is followed by mitogen_via= case to test hostvars pass. + + +# No become-pass set, defaults to "root" +- name: integration/transport_config/become-pass.yml + hosts: tc-become-pass-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" + - out.result[1].kwargs.password == None + +# Not set, unbecoming mitogen_via= +- hosts: tc-become-pass-unset + become: true + vars: {mitogen_via: tc-become-pass-password} + 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 == "ssh" + - out.result[2].method == "sudo" + - out.result[2].kwargs.password == None + +# Not set, becoming mitogen_via= +- hosts: tc-become-pass-unset + become: true + vars: {mitogen_via: viapass@tc-become-pass-password} + tasks: + - include: ../_mitogen_only.yml + - {mitogen_get_stack: {}, register: out} + - assert: + that: + - out.result|length == 4 + - out.result[0].method == "ssh" + - out.result[1].method == "sudo" + - out.result[1].kwargs.password == "apassword" + - out.result[2].method == "ssh" + - out.result[3].method == "sudo" + - out.result[3].kwargs.password == None + + +# ansible_become_password= set. +- hosts: tc-become-pass-password + 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" + - out.result[1].kwargs.password == "apassword" + + +# ansible_become_password=, via= +- hosts: tc-become-pass-password + vars: {mitogen_via: root@tc-become-pass-pass} + become: true + tasks: + - include: ../_mitogen_only.yml + - {mitogen_get_stack: {}, register: out} + - assert: + that: + - out.result|length == 4 + - out.result[0].method == "ssh" + - out.result[1].method == "sudo" + - out.result[1].kwargs.password == "apass" + - out.result[2].method == "ssh" + - out.result[3].method == "sudo" + - out.result[3].kwargs.password == "apassword" + + +# ansible_become_pass= +- hosts: tc-become-pass-pass + 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" + - out.result[1].kwargs.password == "apass" + + +# ansible_become_pass=, via= +- hosts: tc-become-pass-pass + vars: {mitogen_via: root@tc-become-pass-password} + become: true + tasks: + - include: ../_mitogen_only.yml + - {mitogen_get_stack: {}, register: out} + - assert: + that: + - out.result|length == 4 + - out.result[0].method == "ssh" + - out.result[1].method == "sudo" + - out.result[1].kwargs.password == "apassword" + - out.result[2].method == "ssh" + - out.result[3].method == "sudo" + - out.result[3].kwargs.password == "apass" + + + +# ansible_become_pass & ansible_become_password set, password takes precedence +- hosts: tc-become-pass-both + 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" + - out.result[1].kwargs.password == "a.b.c" + + +# both, mitogen_via +- hosts: tc-become-pass-unset + vars: {mitogen_via: root@tc-become-pass-both} + 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 == "sudo" + - out.result[1].kwargs.password == "a.b.c" + - out.result[2].method == "ssh"