我需要在目录中标识一组文件,并使用扩展名.repo重命名所有文件。是否可以使用本机Ansible函数来做到这一点?如果不可能的话,我将使用一个纯硬的shell命令。
对于此答案,ansible不支持移动/重命名功能:https : //stackoverflow.com/questions/24162996/how-to-move-rename-a-file-using-an-ansible-task-on-a-remote -系统
如果您对fileglob谨慎,则可以使用以下方法解决不使用shell的问题:
---
- name: copy files to new names and remove old ones
hosts: all
become: yes
tasks:
- name: copy all .repo files in a spec. directory to new names
copy:
src: "{{ item }}"
dst: whatever_you_want_me_to_be_{{ item }}.reponot
with_fileglob: "/tmp/repofiles/*repo"
- name: remove all .repo files in a spec. directory
file:
path: "{{ item }}"
state: absent
with_fileglob: "/tmp/repofiles/*repo"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句