Loops 使用变量迭代ansible任务

Loops 使用变量迭代ansible任务,loops,ansible,ansible-2.x,Loops,Ansible,Ansible 2.x,我希望获取一个shell命令的输出,并将其用作输入,以将每个项作为和arg运行另一个命令多次: --- - hosts: myhost tasks: - name: determine local storage mount points shell: /usr/sbin/showmount -d | grep -v Directories register: mounts - debug: var=mounts.stdout_lines

我希望获取一个shell命令的输出,并将其用作输入,以将每个项作为和arg运行另一个命令多次:

---
- hosts: myhost
  tasks:

    - name: determine local storage mount points
      shell: /usr/sbin/showmount -d | grep -v Directories
      register: mounts

    - debug: var=mounts.stdout_lines

    - name: run gather script
      shell: echo gather.py {{item}}
      register: gather
      with_items: "{{mounts.stdout_lines}}"

如何做到这一点?

从技术上讲,您的代码是正确的,应该可以工作。但是,
echo-gather.py{{item}
shell
命令可能是您的问题

查看gather的文件扩展名,我怀疑您正在尝试执行python脚本?因此,在这里执行
回音
没有任何意义


相反,您可能希望尝试
python gather.py{{item}}

您的代码似乎是正确的。怎么了?是的。我只是把你们的代码用在了其他东西的模板上。就我而言,关闭docker容器。成功了。你收到任何失败的消息了吗?@yee379我得到的唯一区别是我使用了
command
而不是
shell
参见我的示例:@yee379-你的shell命令看起来不太正确
echo-collect.py{{item}
echo
应该是
python