How to copy remote stdout to local file using Ansible
Ansible is an open-source automation engine that automates software provisioning, configuration management, and application deployment. Playbooks are Ansible’s configuration, deployment, and orchestration language. Playbooks are expressed in YAML format (see YAML Syntax) and have a minimum of syntax, which intentionally tries to not be a programming language or script, but rather a model of a configuration or a process.
This article explains the the configuration of a playbook for copying remote stdout to local file using Ansible.
Open a yaml file in the Ansible installation folder and save the below content to it.
- hosts: all
tasks:
- command: cat /tmp/result.txt
register: store
- local_action: "copy content='{{ store.stdout }}' dest=/etc/ansible/data.txt"
Here the stdout from remote server will be copied to the local file '/etc/ansible/data.txt'.
Now we can execute this playbook to complete the task.