Reputation: 2474
test.yml
---
- hosts: webservers
remote_user: username
tasks:
- name: Execute the script
command: sh /home/username/top.sh
top.sh
#!/bin/bash
top > system.txt
I run test.yml in local machine, it will run the shell script in remote machine and save the command in system.txt file.
location of top.sh: remote, location of system.txt: remote
But I am looking for
location of top.sh: local (but I need to run this command in remote), location of system.txt: local
How to achieve this?
Upvotes: 1
Views: 410
Reputation: 10546
You can use the synchronize
module to copy files from local to remote or from remote to local host. For example
- name: 'Copy run.sh to remote machine'
synchronize:
mode: push
src: top.sh
dest: /home/username
- name: Execute the script
command: sh /home/username/top.sh
- name: 'Copy system.txt to local machine'
synchronize:
mode: pull
src: /home/username/system.txt
dest: .
Note: for the synchronize
module to work you will need to have rsync
installed on the hosts.
Upvotes: 1