Как я могу использовать модуль mv Ansible - PullRequest
0 голосов
/ 11 февраля 2019

Я пытаюсь использовать модуль mv на Ansible, но мне не везет.

В своей первоначальной попытке я сделал следующее:

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

И я получаю следующую ошибку:

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": []}

Итак, я изменил ее на:

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

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

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

Моя новая ошибка:

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

1 Ответ

0 голосов
/ 11 февраля 2019

Похоже, что "модуль копирования для работы с рекурсивом и удаленным_сайтером" пока не работает, но будет поддерживаться с мая 2019 г.

Вот обходной путь, измените имена папок наваши настройки.

# Copy all files and directories from /usr/share/easy-rsa to /etc/easy-rsa

- name: List files in /usr/share/easy-rsa
  find:
    path: /usr/share/easy-rsa
    recurse: yes
    file_type: any
  register: find_result

- name: Create the directories
  file:
    path: "{{ item.path | regex_replace('/usr/share/easy-rsa','/etc/easy-rsa') }}"
    state: directory
    mode: "{{ item.mode }}"
  with_items:
    - "{{ find_result.files }}"
  when:
    - item.isdir

- name: Copy the files
  copy:
    src: "{{ item.path }}"
    dest: "{{ item.path | regex_replace('/usr/share/easy-rsa','/etc/easy-rsa') }}"
    remote_src: yes
    mode: "{{ item.mode }}"
  with_items:
    - "{{ find_result.files }}"
  when:
    - item.isdir == False
...