将文件保存在本地计算机中,该文件是在远程计算机中生成的? [英] save file in local machine which was generate in remote machine?
问题描述
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
我在本地计算机上运行 test.yml ,它将在远程计算机上运行shell脚本,并将命令保存在 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.
top.sh 的位置:远程, system.txt 的位置:远程
location of top.sh: remote, location of system.txt: remote
但是我正在寻找
top.sh 的位置:本地(但我需要在远程运行此命令), system.txt 的位置:本地
location of top.sh: local (but I need to run this command in remote), location of system.txt: local
如何实现?
推荐答案
您可以使用
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: .
注意:要使synchronize
模块正常工作,您需要在主机上安装rsync
.
Note: for the synchronize
module to work you will need to have rsync
installed on the hosts.
这篇关于将文件保存在本地计算机中,该文件是在远程计算机中生成的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!