【问题标题】:In ansible playbook, need to run script and store that output in remote machine在 ansible playbook 中,需要运行脚本并将输出存储在远程机器中
【发布时间】:2017-05-05 08:12:44
【问题描述】:

我编写了 ansible playbook,在远程机器上运行脚本并将该 o/p 仅存储在远程机器中。我已经将该脚本复制到远程机器中,最多可以应对,但输出未存储在输出文件中,以及如何知道该脚本正在运行

---
 - hosts: clinet
   remote_user: root
   tasks:
    - name: copy file to remote machine
      copy: src=/etc/ansible/1.py dest=/tmp/1.py mode=777

    - name: execute python script
      command: python /tmp/1.py > /tmp/1.out

【问题讨论】:

  • 您可能想了解commandshell 模块的区别。另外,请很好地格式化您的问题代码格式选项。

标签: ansible


【解决方案1】:

首先将输出注册到变量中,并将内容添加到文件中。

- name: execute python script
  command: python /tmp/1.py
  register: {{some_var}}

- copy:
    content="{{some_var.stdout}}"
    dest=/path/to/destination/file

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-02
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 2016-06-14
    • 2023-03-23
    • 1970-01-01
    相关资源
    最近更新 更多