Ansible Can';t使用循环复制文件
我正试图用ansible复制许多文件。 这是我的剧本:Ansible Can';t使用循环复制文件,ansible,Ansible,我正试图用ansible复制许多文件。 这是我的剧本: - name: Copy the scenario test copy: src: files/{{ scenario_name }} dest: /home/{{ user }}/scenario_creation mode: '0644' run_once: true loop: "{{ scena
- 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\u 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"
}
有什么帮助吗?更改:
src: files/
到
您需要将代码更改为:
- name: Copy the scenario test
copy:
src: files/{{ item }}
dest: /home/{{ user }}/scenario_creation
mode: '0644'
run_once: true
loop: "{{ scenario_name }}"
tags:
- user
- scenario
循环将列表迭代为术语“item”,除非您使用loop_var选项重新定义它。因此,当您在src行中调用scenario_name时,实际上是在调用整个列表,而不是它的迭代
- name: Copy the scenario test
copy:
src: files/{{ item }}
dest: /home/{{ user }}/scenario_creation
mode: '0644'
run_once: true
loop: "{{ scenario_name }}"
tags:
- user
- scenario