is ~/.bashrc of a become_user read upon TASK execution?

57 views
Skip to first unread message

dulh...@mailbox.org

unread,
Jan 19, 2022, 5:34:29 AM1/19/22
to ansible...@googlegroups.com

can anybody tell me whether the ~/.bashrc of a become_user is being read on TASK execution, so you could rely on aliases, environment variables or PATH to be effective?

Stefan Hornburg (Racke)

unread,
Jan 19, 2022, 5:53:23 AM1/19/22
to ansible...@googlegroups.com
On 19/01/2022 11:34, dulhaver via Ansible Project wrote:
>
> can anybody tell me whether the ~/.bashrc of a become_user is being read on TASK execution, so you could rely on aliases, environment variables or PATH to be effective?
>

As far as know it is not being read. And I doubt that is a good idea if the goal is idempotence.

Regards
Racke

> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1756296122.520131.1642588450250%40office.mailbox.org <https://groups.google.com/d/msgid/ansible-project/1756296122.520131.1642588450250%40office.mailbox.org?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.

OpenPGP_signature

Nico Kadel-Garcia

unread,
Jan 19, 2022, 8:35:26 AM1/19/22
to ansible...@googlegroups.com
On Wed, Jan 19, 2022 at 5:53 AM Stefan Hornburg (Racke)
<ra...@linuxia.de> wrote:
>
> On 19/01/2022 11:34, dulhaver via Ansible Project wrote:
> >
> > can anybody tell me whether the ~/.bashrc of a become_user is being read on TASK execution, so you could rely on aliases, environment variables or PATH to be effective?
> >
>
> As far as know it is not being read. And I doubt that is a good idea if the goal is idempotence.
>
> Regards
> Racke

become_user normally uses sudo, which does not set $HOME or read
.bashrc unless the "sudo -i" options are used. Read "man sudo" for
more understanding.

dulh...@mailbox.org

unread,
Jan 19, 2022, 10:38:49 AM1/19/22
to ansible...@googlegroups.com
On 19.01.22 11:53, Stefan Hornburg (Racke) wrote:
> On 19/01/2022 11:34, dulhaver via Ansible Project wrote:
>>
>> can anybody tell me whether the ~/.bashrc of a become_user is being
>> read on TASK execution, so you could rely on aliases, environment
>> variables or PATH to be effective?
> As far as know it is not being read. And I doubt that is a good idea
> if the goal is idempotence.
ok, thx

Roland Müller

unread,
Jan 21, 2022, 2:15:24 AM1/21/22
to Ansible Project
But doesn't reading of .bashrc and other bash files depend on the Ansible module that is used, and whether the module executes inside a bash shell?
 E.g., module 'shell' uses the bash shell unless some other shell is configured explicitly. Thus, one can execute remote with 'shell' commands with the same settings as in interactive login.

BR,
Roland

dulh...@mailbox.org

unread,
Jan 21, 2022, 3:32:52 AM1/21/22
to ansible...@googlegroups.com
I was not thinking about shell module tbh.

Still, do I understand you correctly that you mean something like
   ... .bashrc may not be read for most of Ansible modules but it is read for shell and maybe command module?

Roland Müller

unread,
Jan 21, 2022, 9:20:59 AM1/21/22
to Ansible Project
I mean .bashrc is only read when the used ansible module uses bash. The become_user functionality - that is done before the module execution - does not use bash (as others already answered above).

The command module executes the provided command as such and shell uses a shell (normally bash) to execute the command.
 

Todd Lewis

unread,
Jan 21, 2022, 10:06:16 AM1/21/22
to Ansible Project
Only, .bashrc isn't run by the shell module even if bash is used. Testing by adding
export BASHRC_RAN="# bashrc ran"
to .bashrc and running the shell module to
echo $BASHRC_RAN
bears this out.

Brian Coca

unread,
Jan 21, 2022, 11:09:14 AM1/21/22
to Ansible Project
Ansible executes in 'batch mode' aka non-interactive, bash normally
does not execute .bashrc in this case (it can be setup to do so, but
most distros default to not do so)



--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages