将输出写入本地文件并从Ansible for Windows中的Control Machine中获取

时间:2019-05-20 22:15:29

标签: ansible

我已经在Windows主机上为我的剧本(在Linux主机中工作的 )测试了以下任务,但似乎没有成功

  - name: Create local report
    delegate_to: localhost
    file:
      dest: /tmp/report.csv
      state: touch

  - name: fetch file
    local_action:
      module: lineinfile
      dest: /tmp/report.csv
      line: "{{ output.stdout_lines }}"
      insertafter: EOF

我不知道Windows主机上是否有用于执行类似任务的特殊模块。

1 个答案:

答案 0 :(得分:0)

您正在使用delegate_to: localhostlocal_action。这意味着这两个操作都在运行剧本的服务器上执行(您可以在here中查找有关委托的其他信息)。这应该可行:

    - name: Create local report
      file:
        dest: /tmp/report.csv
        state: touch

    - name: fetch file
      lineinfile:
        dest: /tmp/report.csv
        line: "{{ output.stdout_lines }}"
        insertafter: EOF
相关问题