首页 > 解决方案 > 无法使用循环复制文件

问题描述

我正在尝试使用 ansible 复制许多文件。这是我的剧本:

- name: Copy the scenario test 
        copy: 
            src: files/{{ scenario_name }} 
            dest: /home/{{ user }}/scenario_creation 
            mode: '0644' 
            run_once: true 
        loop: "{{ scenario_name }}" 
        tags: 
            - user 
            - scenario 

这是我的角色/scenario_test/defaults/main.yml

scenario_name: ['topup-scenario.json', 'test.json'] 

当我执行我的剧本时,它说:

"msg": "Could not find or access 'files/[u'topup-scenario.json', u'test.json']'\nSearched in:\n\t/home/path/ansible/plays/files/[u'topup-scenario.json', u'test.json']\n\t/home/path/ansible/plays/files/[u'topup-scenario.json', u'test.json'] on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"
}

有什么帮助吗?

标签: ansible

解决方案


改变:

src: files/

 src: ./files/

推荐阅读