Ansible:复制文件时如何重命名文件
Ansible : how to rename a file when copying it
我有一个任务,我应该从哪里复制一个文件到它的目的地,同时在目的地重命名它。
我的任务是这样的:
- 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 it to: renamed.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
备注:
-
想想你应该如何处理多个文件。
在上面的例子中 - 只复制第一个
我有一个任务,我应该从哪里复制一个文件到它的目的地,同时在目的地重命名它。
我的任务是这样的:
- 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 it to:
renamed.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
备注:
想想你应该如何处理多个文件。
在上面的例子中 - 只复制第一个