Get copy src from variable

33 views
Skip to first unread message

Dimitri Yioulos

unread,
Feb 14, 2024, 9:00:01 AM2/14/24
to Ansible Project
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.

Todd Lewis

unread,
Feb 14, 2024, 10:21:38 AM2/14/24
to ansible...@googlegroups.com, uto...@gmail.com
- { src: "{{ var_containing_package1 }}" }
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/52e9d6e8-cbb1-4a5d-9b96-87360303b12bn%40googlegroups.com.

Dimitri Yioulos

unread,
Feb 14, 2024, 12:35:25 PM2/14/24
to Ansible Project
Thank you, Todd! That works. I thought I had tried that previously, and it failed. I must have done it wrong.
Reply all
Reply to author
Forward
0 new messages