Skip to content

Commit 535c037

Browse files
authored
Merge branch 'master' into feature/handle-tempdir-not-existing
2 parents cfb836c + bb9c51b commit 535c037

File tree

10 files changed

+67
-15
lines changed

10 files changed

+67
-15
lines changed

.ci/ansible_tests.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import signal
88
import sys
9+
import textwrap
910

1011
import ci_lib
1112

@@ -74,7 +75,15 @@ def pause_if_interactive():
7475
fp.write('\n[%s]\n' % family)
7576
fp.writelines('%s\n' % name for name in hostnames)
7677

77-
fp.write('\n[linux:children]\ntest-targets\n')
78+
fp.write(textwrap.dedent(
79+
'''
80+
[linux:children]
81+
test-targets
82+
83+
[linux_containers:children]
84+
test-targets
85+
'''
86+
))
7887

7988
ci_lib.dump_file(inventory_path)
8089

ansible_mitogen/transport_config.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
except ImportError:
8080
from ansible.vars.unsafe_proxy import AnsibleUnsafeText
8181

82-
import ansible_mitogen.loaders
8382
import mitogen.core
8483

8584

@@ -436,9 +435,18 @@ def become_user(self):
436435
return self._play_context.become_user
437436

438437
def become_pass(self):
439-
become_method = self.become_method()
440-
become_plugin = ansible_mitogen.loaders.become_loader.get(become_method)
441-
become_pass = become_plugin.get_option('become_pass', hostvars=self._task_vars)
438+
# become_pass is owned/provided by the active become plugin. However
439+
# PlayContext is intertwined with it. Known complications
440+
# - ansible_become_password is higher priority than ansible_become_pass,
441+
# `play_context.become_pass` doesn't obey this (atleast with Mitgeon).
442+
# - `meta: reset_connection` runs `connection.reset()` but
443+
# `ansible_mitogen.connection.Connection.reset()` recreates the
444+
# connection object, setting `connection.become = None`.
445+
become_plugin = self._connection.become
446+
try:
447+
become_pass = become_plugin.get_option('become_pass', playcontext=self._play_context)
448+
except AttributeError:
449+
become_pass = self._play_context.become_pass
442450
return optional_secret(become_pass)
443451

444452
def password(self):

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ To avail of fixes in an unreleased version, please download a ZIP file
2121
Unreleased
2222
----------
2323
* :gh:issue:`1061` Fix recreating temp directory if it has been removed mid-play
24+
* :gh:issue:`952` Fix Ansible `--ask-become-pass`, add test coverage
2425

2526
v0.3.7 (2024-04-08)
2627
-------------------

tests/ansible/hosts/default.hosts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ target ansible_host=localhost ansible_user="{{ lookup('pipe', 'whoami') }}"
1010

1111
[test-targets]
1212
target
13+
14+
[linux_containers]

tests/ansible/integration/interpreter_discovery/complex_args.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,18 @@
2929
special_python: "source /tmp/fake || true && python{{ ansible_facts.python.version.major }}"
3030

3131
- name: run get_url with specially-sourced python
32-
get_url:
32+
uri:
3333
# Plain http for wider Ansible & Python version compatibility
34-
url: http://httpbin.org/get
35-
dest: "/tmp/"
36-
mode: 0644
34+
url: http://www.gstatic.com/generate_204
35+
status_code: [204]
3736
vars:
3837
ansible_python_interpreter: "{{ special_python }}"
3938

4039
- name: run get_url with specially-sourced python including jinja
41-
get_url:
40+
uri:
4241
# Plain http for wider Ansible & Python version compatibility
43-
url: http://httpbin.org/get
44-
dest: "/tmp/"
45-
mode: 0644
42+
url: http://www.gstatic.com/generate_204
43+
status_code: [204]
4644
vars:
4745
ansible_python_interpreter: >
4846
{% if "1" == "1" %}

tests/ansible/integration/transport_config/become_pass.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@
143143
- out.result|length == 2
144144
- out.result[0].method == "ssh"
145145
- out.result[1].method == "sudo"
146-
# Ansible >= 2.10 builtin become plugins (e.g. sudo, su) give priority
147-
# to ansible_become_pass over ansible_become_password.
146+
# Ansible <= 2.9.1 prioritises ansible_become_password.
147+
# Ansible >= 2.9.2 prioritises ansible_become_pass.
148+
# https://github.com/ansible/ansible/commit/480b106d6535978ae6ecab68b40942ca4fa914a0
148149
- out.result[1].kwargs.password == "bpass"
149150
fail_msg: out={{out}}
150151
tags:

tests/ansible/regression/all.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
- import_playbook: issue_615__streaming_transfer.yml
1515
- import_playbook: issue_655__wait_for_connection_error.yml
1616
- import_playbook: issue_776__load_plugins_called_twice.yml
17+
- import_playbook: issue_952__ask_become_pass.yml
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- name: regression/become_test.yml
2+
hosts: test-targets:&linux_containers
3+
become: true
4+
become_user: mitogen__pw_required
5+
strategy: mitogen_linear
6+
tasks:
7+
- command: whoami
8+
changed_when: false
9+
check_mode: false
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
- name: regression/issue_952__ask_become_pass.yml
2+
hosts: test-targets[0]:&linux_containers
3+
gather_facts: false
4+
tags:
5+
- issue_952
6+
tasks:
7+
- name: Test --ask-become-pass
8+
delegate_to: localhost
9+
expect:
10+
command: >
11+
ansible-playbook
12+
{% for inv in ansible_inventory_sources %}
13+
-i "{{ inv }}"
14+
{% endfor %}
15+
--ask-become-pass
16+
regression/become_test.yml
17+
chdir: ../
18+
responses:
19+
'BECOME password:': pw_required_password
20+
changed_when: false
21+
check_mode: false

tests/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Django==3.2.20; python_version >= '3.6'
1212
mock==3.0.5; python_version == '2.7'
1313
mock==5.1.0; python_version >= '3.6'
1414

15+
pexpect==4.8
16+
1517
psutil==5.9.8
1618

1719
pytest==4.6.11; python_version == '2.7'

0 commit comments

Comments
 (0)