Table of Contents

Ansible

Make Output human readable

ansible.cfg
[default]
stdout_callback=debug

References:

User 'delegate_to' with a different remote user

Although remote_user ought to work by task with delegate_to1) it doen't when I tried. Following approaches in the task specification did the trick:

Using 'become'

- name: Sample delegate_to task with become
  delegate_to: other_host
  become: yes
  become_user: other_user
  shell: |
    id
    whoami
  register: shell

- name: Print stdout and stderr
  debug:
    msg: "OUT:\n{{ shell.stdout}}\nERROR:\n{{ shell.stderr }}"

References:

Using 'ansible_user'

- name: Sample delegate_to task with ansible_user: other_user
  delegate_to: other_host
  vars:
    ansible_user: other_user
  shell: |
    id
    whoami
  register: shell

- name: Print stdout and stderr
  debug:
    msg: "OUT:\n{{ shell.stdout}}\nERROR:\n{{ shell.stderr }}"

Adding user to 'delegate_to'

I consider this dirty

- name: Sample delegate_to task with other_user@other_host
  delegate_to: other_user@other_host
  shell: |
    id
    whoami
  register: shell

- name: Print stdout and stderr
  debug:
    msg: "OUT:\n{{ shell.stdout}}\nERROR:\n{{ shell.stderr }}"

References: