# How to specify the user home directory dynamatically with /home/{{ 'echo{$USER}' }}/sub\_dir for copying files with Ansible copy module ?

**URL:** <https://forum.ansible.com/t/how-to-specify-the-user-home-directory-dynamatically-with-home-echo-user-sub-dir-for-copying-files-with-ansible-copy-module/32022>\
**Category:** Ansible Project\
**Tags:** gcp\
**Created:** [January 22, 2020, 2:07am UTC](https://forum.ansible.com/t/how-to-specify-the-user-home-directory-dynamatically-with-home-echo-user-sub-dir-for-copying-files-with-ansible-copy-module/32022 "2020-01-22T02:07:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FRANK\_L](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@FRANK\_L](https://forum.ansible.com/u/FRANK_L)\
**Post date:** [January 22, 2020, 2:07am UTC](https://forum.ansible.com/t/how-to-specify-the-user-home-directory-dynamatically-with-home-echo-user-sub-dir-for-copying-files-with-ansible-copy-module/32022/1 "2020-01-22T02:07:44Z")

</div>

Hi,

I would like to use git for managing Ansible playbooks for version control on an admin server in GCP. So the idea is this:

each user in the admin group to run the playbooks pulled from the github ino their repo from each user’s home. for exampel:  
for user1,  
run ansible playbooks from: adminserver:/home/user1/user1\_git\_repo/playbooks

for user1,  
run ansible playbooks from: adminserver:/home/user2/user2\_git\_repo/playbooks

etc.

I have this Ansible playbook but it doesn’t work:

---

<div class="post-metadata">

**Author:** ![Michael\_M1](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michael\_M1](https://forum.ansible.com/u/Michael_M1)\
**Post date:** [January 22, 2020, 3:26am UTC](https://forum.ansible.com/t/how-to-specify-the-user-home-directory-dynamatically-with-home-echo-user-sub-dir-for-copying-files-with-ansible-copy-module/32022/2 "2020-01-22T03:26:53Z")

</div>

Frank,

Something like this should work:

> - name: Copy the sudoers file from ~/managed\_files/sudo\_ii/sudoers to /etc on the remote VMs  
> copy:  
> src: "{{ lookup(‘env’,HOME) }}/managed\_files/sudo\_ii/sudoers  
> dest: /etc  
> owner: root  
> group: root  
> mode: ‘0440’

See [https://docs.ansible.com/ansible/latest/plugins/lookup/env.html](https://docs.ansible.com/ansible/latest/plugins/lookup/env.html)

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [January 22, 2020, 2:14pm UTC](https://forum.ansible.com/t/how-to-specify-the-user-home-directory-dynamatically-with-home-echo-user-sub-dir-for-copying-files-with-ansible-copy-module/32022/3 "2020-01-22T14:14:10Z")

</div>

Also, use the ‘validate’ parameter when you’re deploying sudoers files.  
Without this, mistakes can cause you to completely lose access.

---

<div class="post-metadata">

**Author:** ![FRANK\_L](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@FRANK\_L](https://forum.ansible.com/u/FRANK_L)\
**Post date:** [January 22, 2020, 3:18pm UTC](https://forum.ansible.com/t/how-to-specify-the-user-home-directory-dynamatically-with-home-echo-user-sub-dir-for-copying-files-with-ansible-copy-module/32022/4 "2020-01-22T15:18:14Z")

</div>

Hi Michael,

Thanks for the tip. Yes, it works.

Frank

---

<div class="post-metadata">

**Author:** ![FRANK\_L](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@FRANK\_L](https://forum.ansible.com/u/FRANK_L)\
**Post date:** [January 22, 2020, 4:33pm UTC](https://forum.ansible.com/t/how-to-specify-the-user-home-directory-dynamatically-with-home-echo-user-sub-dir-for-copying-files-with-ansible-copy-module/32022/5 "2020-01-22T16:33:30Z")

</div>

Dick,

Thanks for the suggestion.

We use visudo for editing the sudoers file in the first place. So if any mistakes made we could catch up in the first place.

Your suggestion is the good one, and I like it.

Frank
