Ansible:复制文件时如何重命名文件
我有一个任务,我应该在哪里将文件从其源复制到其目标,同时在目标中重命名它 我的任务如下所示:Ansible:复制文件时如何重命名文件,ansible,ansible-2.x,Ansible,Ansible 2.x,我有一个任务,我应该在哪里将文件从其源复制到其目标,同时在目标中重命名它 我的任务如下所示: - name: Go to the target folder shell: ls args: chdir: "{{pathTest}}/target" register: resultLS - debug: msg: "{{resultLS}}" - name: copy jar file copy: src: "{{resultLS.stdout}}" des
- name: Go to the target folder
shell: ls
args:
chdir: "{{pathTest}}/target"
register: resultLS
- debug:
msg: "{{resultLS}}"
- name: copy jar file
copy:
src: "{{resultLS.stdout}}"
dest: "{{pathTest}}"
mode: 0777
但是,像这样,它用相同的名称复制jar文件,我的目的是如何在dest
中重命名它(理想情况下使用复制操作)
创意?
将其重命名为:rename.jar
给你:
- name: Ensure the first matched file from {{ pathTest }}/target is present on the target
copy:
src: "{{ lookup('fileglob', pathTest + '/target/*') | first }}"
dest: "{{ pathTest }}/renamed.jar"
mode: 0777
备注:
- 思考如何处理多个文件 在上面的示例中-仅复制第一个
rename.jar
给你:
- name: Ensure the first matched file from {{ pathTest }}/target is present on the target
copy:
src: "{{ lookup('fileglob', pathTest + '/target/*') | first }}"
dest: "{{ pathTest }}/renamed.jar"
mode: 0777
备注:
- 思考如何处理多个文件 在上面的示例中-仅复制第一个