User Tools

Site Tools


docs:tips_n_tricks:ansible.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
docs:tips_n_tricks:ansible.html [17.12.2022 15:45 CET] – created peterdocs:tips_n_tricks:ansible.html [07.01.2023 12:35 CET] (current) – [User 'delegate_to' with a different remote user] peter
Line 7: Line 7:
 __References:__ __References:__
   * https://github.com/ansible/ansible/issues/27078   * https://github.com/ansible/ansible/issues/27078
 +===== User 'delegate_to' with a different remote user =====
 +Although ''remote_user'' ought to work by task with ''delegate_to''((cf.\\ [[https://github.com/ansible/ansible/issues/13323|Github closed issue - delegate_to with remote_user on ansible 2.0 #13323]],\\ [[https://www.reddit.com/r/ansible/comments/poczx3/delegate_to_and_another_user/|Reddit - Delegate_to and another user]],\\ [[https://groups.google.com/g/ansible-project/c/-gr3k70JNlw|google.groups - Indicating username with delegate_to]] )) it doen't when I tried.
 +Following approaches in the task specification did the trick:
 +==== Using 'become' ====
 +<code yaml>
 +- 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 }}"
 +</code>
 +
 +__References__:
 +  * [[https://stackoverflow.com/questions/38660246/ansible-delegate-to-how-to-set-user-that-is-used-to-connect-to-target | Stackoverflow - Ansible delegate_to how to set user that is used to connect to target?]]
 +==== Using 'ansible_user' ====
 +<code yaml>
 +- 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 }}"
 +</code>
 +==== Adding user to 'delegate_to' ====
 +//I consider this dirty//
 +<code yaml>
 +- 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 }}"
 +</code>
 +
 +__References__:
 +  * [[https://mjs.fyi/2018/03/20/ansible-quirks-delegating-a-task-with-a-unique-remote-user/|mjs.fyi - Ansible quirks: Delegating a task with a unique remote user]]
docs/tips_n_tricks/ansible.html.1671288359.txt.gz · Last modified: 17.12.2022 15:45 CET by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki