How can I use the mv module Ansible


February 2019


9 time


I am trying to use the mv module on Ansible but I am not having luck.

In my initial attempt I did the following:

- name: changing the name of the file
  shell: mv /tmp/bundle /opt/Rocket.Chat

And I get the following error:

FAILED! => {"changed": true, "cmd": "mv /tmp/bundle /opt/Rocket.Chat", "delta": "0:00:00.033553", "end": "2019-02-11 06:06:43.273787", "msg": "non-zero return code", "rc": 1, "start": "2019-02-11 06:06:43.240234", "stderr": "mv: cannot move ‘/tmp/bundle’ to ‘/opt/Rocket.Chat/bundle’: File exists", "stderr_lines": ["mv: cannot move ‘/tmp/bundle’ to ‘/opt/Rocket.Chat/bundle’: File exists"], "stdout": "", "stdout_lines": []}

So, I changed it to:

   - name: create directory
         state: directory
         path: "/opt/Rocket.Chat"

   - name: copy the files
          src: "/tmp/bundle"
          dest: "/opt/Rocket.Chat"
          remote_src: yes

    - name: delete the other files
        file: path=/tmp/bundle state=absent

My new error is:

FAILED! => {"changed": false, "msg": "Remote copy does not support recursive copy of directory: /tmp/bundle"}

1 answers


Попробуйте первую версию с:

become: true