Siva
Siva

Reputation: 65

In ansible playbook, need to run script and store that output in remote machine

I wrote ansible playbook, to run the script in remote machine and store that o/p in the remote machine only. I have copied that script into remote machine, upto coping is working, but output is not storing in output file and how to know that script is running

---
 - 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

Upvotes: 1

Views: 2675

Answers (1)

MMA
MMA

Reputation: 458

First register the output into variable and add the content to the file.

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

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

Upvotes: 2

Related Questions