我有一个项目,需要我从远程服务器获取多个文件的内容并传入文件。通过web服务器上的多个文件进行交互
这里是任务,我创建了用于实现该目标:
- name: check content
uri:
url: http://172.16.2.3/file1
method: GET
return_content: yes
register: file1
- name: print content
debug: msg={{file1.content}}
调试内容显示以下
ok: [172.16.2.4] => {
"changed": false,
"msg": "testcontent11111\n"
但是因为我必须通过多个文件循环,我试过如下:
- name: check content
uri:
url: http://172.16.2.3/{{item.url}}
method: GET
return_content: yes
register: {{item.register}}
with_items:
- { url: 'file1', register: 'file1' }
- name: print content
debug: msg={{file1.content}}
不幸的是调试上面的内容在m y输出
FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'file1' is undefined\
任何想法如何我可以写第二个任务来完成第一个目标?
+1
的可能的复制[注册变量与\ _items在Ansible剧本环路(https://stackoverflow.com/questions/29512443/register-variables-in-with-items-loop -in-ansible-playbook) - 并且无法在循环中注册具有任意名称的变量。 –