I have made a playbook which does something like this:
shell: source ~/.bashrc && some_command |awk something more
become: yes
become user: a_user
become_method: sudo
My Ansible_user that connects to the target host should not be able to sudo -i on target host, nor should it have 'Ansible_user (ALL)=ALL NOPASSWD: ALL' entry in the /etc/sudoers.
I want it to be able to execute some commands as a_user (including bash builtins like source). I found in the documentation that Ansible will try to execute something like this:
1. log on as Ansible_user
2. Execute $Ansible_user sudo -u commands_from_playbook
Yet, when I try to run the playbook all I get is:
module_stderr: Shared connection to host_ip_here closed
msg: MODULE FAILURE See stderr for the exact error
No stderr is presented despite the job running as 'verbosity 3'
When user is granted sudo -i and/or ALL in sudoers, the script runs as expected...
What should be the /etc/sudoers entry? Probably I should use something like
Ansible_user ALL = (a_user) NOPASSWD: and_something_here (/bin/bash for builtins?)
Any hints?
Asked by just_a_noob
(101 rep)
Dec 29, 2022, 03:01 PM
Last activity: Jan 22, 2025, 09:40 PM
Last activity: Jan 22, 2025, 09:40 PM