0

I have a destination for file copy as a variable file_path, how can I copy files to that destination using template/copy modules?

Tried:

---
- hosts: localhost
  connection: local

  tasks:
  - name: variable
    command: echo "emptyDir"
    register: file_path

  - name: check var value
    debug:
      var: file_path
      verbosity: 2

  - name: copy mod
    template:
      src: "{{ item }}"
      dest: "{{ file_path }}"
      mode: 0755
    with_items:
      - "file1.txt"
      - "file2.txt"

Error: If copy module is used copyModule error

If template module is used templateModule error

But throws some dict - string error.

Any help is appreciated.

TIA

r0r0n0a
  • 173
  • 2
  • 2
  • 10
  • Hi. Please see [How to ask](https://stackoverflow.com/help/how-to-ask), more specifically the paragraph concerning code and errors in images. Edit your question to fix this. Thanks. – Zeitounator Jun 18 '20 at 07:08
  • Please share the value of `file_path` as well. I think the problem lies within the value you have used for `file_path` – Shubham Vaishnav Jun 18 '20 at 07:17
  • If you just have to copy the files without having anything in the file which needs to be resolved like jinja2 template then use copy module, otherwise use template module. – Shubham Vaishnav Jun 18 '20 at 07:20
  • @Shubham Vaishnav, Yes it worked with copy module itself but had to pass only stdout part of the variable. Else it is giving the entire output of variable which is a dictionary. Thanks for help – r0r0n0a Jun 18 '20 at 15:22

1 Answers1

0

Check the issue could be with stdout, need to use file_path.stdout. Else it will be a dictionary.

Zarak1
  • 103
  • 10