# is ~/.bashrc of a become\_user read upon TASK execution?

**URL:** <https://forum.ansible.com/t/is-bashrc-of-a-become-user-read-upon-task-execution/36222>\
**Category:** Ansible Project\
**Created:** [January 19, 2022, 10:34am UTC](https://forum.ansible.com/t/is-bashrc-of-a-become-user-read-upon-task-execution/36222 "2022-01-19T10:34:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [January 19, 2022, 10:34am UTC](https://forum.ansible.com/t/is-bashrc-of-a-become-user-read-upon-task-execution/36222/1 "2022-01-19T10:34:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [January 19, 2022, 10:53am UTC](https://forum.ansible.com/t/is-bashrc-of-a-become-user-read-upon-task-execution/36222/2 "2022-01-19T10:53:02Z")

</div>

> 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  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Nico\_Kadel-Garcia](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nico_kadel-garcia/32/9998_2.png) [@Nico\_Kadel-Garcia](https://forum.ansible.com/u/Nico_Kadel-Garcia)\
**Post date:** [January 19, 2022, 1:35pm UTC](https://forum.ansible.com/t/is-bashrc-of-a-become-user-read-upon-task-execution/36222/3 "2022-01-19T13:35:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [January 19, 2022, 3:38pm UTC](https://forum.ansible.com/t/is-bashrc-of-a-become-user-read-upon-task-execution/36222/4 "2022-01-19T15:38:33Z")

</div>

ok, thx

---

<div class="post-metadata">

**Author:** ![rolandm](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rolandm/32/755_2.png) [@rolandm](https://forum.ansible.com/u/rolandm)\
**Post date:** [January 21, 2022, 7:15am UTC](https://forum.ansible.com/t/is-bashrc-of-a-become-user-read-upon-task-execution/36222/5 "2022-01-21T07:15:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [January 21, 2022, 8:32am UTC](https://forum.ansible.com/t/is-bashrc-of-a-become-user-read-upon-task-execution/36222/6 "2022-01-21T08:32:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rolandm](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rolandm/32/755_2.png) [@rolandm](https://forum.ansible.com/u/rolandm)\
**Post date:** [January 21, 2022, 2:20pm UTC](https://forum.ansible.com/t/is-bashrc-of-a-become-user-read-upon-task-execution/36222/7 "2022-01-21T14:20:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [January 21, 2022, 3:06pm UTC](https://forum.ansible.com/t/is-bashrc-of-a-become-user-read-upon-task-execution/36222/8 "2022-01-21T15:06:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 21, 2022, 4:08pm UTC](https://forum.ansible.com/t/is-bashrc-of-a-become-user-read-upon-task-execution/36222/9 "2022-01-21T16:08:44Z")

</div>

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)
