User Tools

Site Tools


docs:tips_n_tricks:ansible.html

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:

docs/tips_n_tricks/ansible.html.txt · Last modified: 07.01.2023 12:35 CET by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki