# How to switch to the application account?

**URL:** <https://forum.ansible.com/t/how-to-switch-to-the-application-account/3415>\
**Category:** Get Help\
**Tags:** playbook\
**Created:** [January 21, 2024, 6:12pm UTC](https://forum.ansible.com/t/how-to-switch-to-the-application-account/3415 "2024-01-21T18:12:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jelmouss](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jelmouss/32/9457_2.png) [@jelmouss](https://forum.ansible.com/u/jelmouss)\
**Post date:** [January 21, 2024, 6:12pm UTC](https://forum.ansible.com/t/how-to-switch-to-the-application-account/3415/1 "2024-01-21T18:12:22Z")

</div>

Don’t know if i have to write this subject in french or english so i go with english (sorry for my english rough spelling)

I have a playbook that can only be run with the application account.

The paths are hard-coded (for the moment) but I would like to use a variable to make this dynamic.  
but unfornately don’t still know how to do ?  
The application account looks like something like this:

```auto
abcpzzz
{sort}{env}zzz

```

The playbook is simple and looks like something like this:

```auto
The playbook looks something like this.
- name: Compress directory /abcpzzz/path/to/foo/ into /path/to/foo.tgz
   community.general.archive:
     path: /abcpzzz/path/to/foo
     dest: /abcpzzz/path/to/foo.tgz

```

How to call all the path properly in a variable ?

---

<div class="post-metadata">

**Author:** ![jelmouss](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jelmouss/32/9457_2.png) [@jelmouss](https://forum.ansible.com/u/jelmouss)\
**Post date:** [January 21, 2024, 6:19pm UTC](https://forum.ansible.com/t/how-to-switch-to-the-application-account/3415/2 "2024-01-21T18:19:16Z")

</div>

Sorry for everyone who will read my post.  
i forgot to start by i simple “hello” and finish as well by i simple “thanks”

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [January 21, 2024, 7:31pm UTC](https://forum.ansible.com/t/how-to-switch-to-the-application-account/3415/3 "2024-01-21T19:31:22Z")

</div>

Have you referenced [Using Variables — Ansible Documentation](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html) ?

---

<div class="post-metadata">

**Author:** ![jelmouss](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jelmouss/32/9457_2.png) [@jelmouss](https://forum.ansible.com/u/jelmouss)\
**Post date:** [January 21, 2024, 8:17pm UTC](https://forum.ansible.com/t/how-to-switch-to-the-application-account/3415/4 "2024-01-21T20:17:04Z")

</div>

Thanks for your response.  
Of course i have referred to the ansible doc, but my real probem is not how to use a variable is how select the right application account (which is in /etc/passwd) to switch automatically to application account when playbook log on the server the run the play.

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [January 21, 2024, 10:16pm UTC](https://forum.ansible.com/t/how-to-switch-to-the-application-account/3415/5 "2024-01-21T22:16:10Z")

</div>

If I am understanding you correctly, maybe you need to use host variables in your inventory - [How to build your inventory — Ansible Documentation](https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#assigning-a-variable-to-one-machine-host-variables)

Or else read `/etc/passwd` in one task, and then set `become_user` and/or other variables based on what you see in the file?

If neither of these help, then you may need to expand on what you are doing - provide a more detailed playbook, provide the expected and actual results, maybe provide how you manually do it … It’s a bit unclear (to me at least) on what the ultimate goal is…

---

<div class="post-metadata">

**Author:** ![jelmouss](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jelmouss/32/9457_2.png) [@jelmouss](https://forum.ansible.com/u/jelmouss)\
**Post date:** [January 22, 2024, 10:38am UTC](https://forum.ansible.com/t/how-to-switch-to-the-application-account/3415/6 "2024-01-22T10:38:27Z")

</div>

i’m talking and asking about how to use “ansible\_env.HOME” in the playbook to Set the remote environment

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [January 23, 2024, 2:54pm UTC](https://forum.ansible.com/t/how-to-switch-to-the-application-account/3415/7 "2024-01-23T14:54:40Z")

</div>

Again, please provide more information - full playbooks, results using `-vvv`, expected/actual results, results running manually, etc., so that people can provide more feedback.

If you are talking about using setting the remote Environment Variables within Ansible, please refer to [Setting the remote environment — Ansible Documentation](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_environment.html)
