Skip to content

Commit fe21a35

Browse files
authored
Fix ansible_user detection condition (#1635)
The previous solution relied on matching against ANSI control codes which was brittle. This broke (again) on Ansible 2.20 because color codes are now displayed which breaks this `intersect` substring match expression. The simpler solution is to just check for the Ansible `CHANGED` output which means the raw command and connection succeeded.
1 parent a8b88f1 commit fe21a35

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

roles/connection/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
- block:
4444
- name: Set remote user for each host
4545
set_fact:
46-
ansible_user: "{{ ansible_user | default((connection_status.stdout_lines | intersect(['root', '\e[0;32mroot', '\e[0;33mroot']) | count) | ternary('root', admin_user)) }}"
46+
ansible_user: "{{ ansible_user | default(('| CHANGED |' in connection_status.stdout) | ternary('root', admin_user)) }}"
4747
check_mode: no
4848

4949
- name: Announce which user was selected

0 commit comments

Comments
 (0)