# Get copy src from variable

**URL:** <https://forum.ansible.com/t/get-copy-src-from-variable/38688>\
**Category:** Ansible Project\
**Created:** [February 14, 2024, 2:00pm UTC](https://forum.ansible.com/t/get-copy-src-from-variable/38688 "2024-02-14T14:00:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [February 14, 2024, 2:00pm UTC](https://forum.ansible.com/t/get-copy-src-from-variable/38688/1 "2024-02-14T14:00:01Z")

</div>

I have plays in a playbook to copy files to a remote host, then delete them at the end of the task list. This is the copy play:

**- name: Copy files to host**  
**copy:**  
**src: “{{ item.src }}”**  
**dest: /tmp**  
**mode: u=rwx,g=rw,o=rw**  
**with\_items:**  
**- { src: package1 }**  
**- { src: file1 }**  
**- { src: file2 }**  
**tags: copy\_files**

package1 is changeable, from time-to-time. I’d like to add the name as a variable, then call the variable in both the copy and delete plays, so that I only have to change the package name once. How can I accomplish that? All of my attempts have failed.

---

<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:** [February 14, 2024, 3:21pm UTC](https://forum.ansible.com/t/get-copy-src-from-variable/38688/2 "2024-02-14T15:21:21Z")

</div>

```auto
- { src: "{{ var_containing_package1 }}" }

```

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [February 14, 2024, 5:35pm UTC](https://forum.ansible.com/t/get-copy-src-from-variable/38688/3 "2024-02-14T17:35:25Z")

</div>

Thank you, Todd! That works. I thought I had tried that previously, and it failed. I must have done it wrong.
