Ansible如何复制到具有动态后缀的目标文件夹

问题描述

我需要将本地源文件夹的内容复制到远程文件夹,其中源内容如下:

files/
├── certs
    ├── server.crt
    └── server.key

目标路径将随其后缀而变化。例如,如果目标路径是claim-pvc-3b6165b0-f1d6-11ea-a39b-0050569b0faf/。这里的claim-pvc-始终保持不变,但是其后缀3b6165b0-f1d6-11ea-a39b-0050569b0faf将会改变。

我尝试使用以下方法,但是没有用:

- name: copy contents
  copy:
    dest: "claim-pvc-*"
    src: files/certs/

请帮助我,这是ansible的初学者。

更新

如评论中所建议。我试图使用find模块来获取目录的全名:

- name: find the
  find:
    paths: "/mnt/k8sMount/"
    patterns: "claim-pvc"
    file_type: "directory"
  register: find_result

- name: print find_result
  debug: var=find_result

但是无法获取目录名称。这就是结果

ok: [master] => {
    "find_result": {
        "changed": false,"examined": 28,"failed": false,"files": [],"matched": 0,"msg": ""
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...