Ansible mail picks attachment from remote hosts
A nice Ansible question!
To pick up an attachment from a remote host using Ansible, you can use the fetch
module. Here's an example of how you can do it:
- name: Fetch attachment from remote host
fetch:
src: /path/to/attachment
dest: /local/path
flat: yes
delegate_to: "{{ inventory_hostname }}"
In this example, fetch
is used to retrieve the file /path/to/attachment
from the remote host and save it to /local/path
on the Ansible control machine. The delegate_to
parameter specifies that the task should be executed on the remote host, rather than on the Ansible control machine.
You can also use the get_url
module to achieve this:
- name: Fetch attachment from remote host
get_url:
url: "scp://{{ inventory_hostname }}:/path/to/attachment"
dest: /local/path
In this example, get_url
is used to retrieve the file /path/to/attachment
from the remote host using SCP (Secure Copy) protocol. The url
parameter specifies the URL of the file to retrieve, and the dest
parameter specifies the local path where the file should be saved.
Make sure to replace {{ inventory_hostname }}
with the actual hostname or IP address of the remote host.
Also, you can use win_get_url
module if you are working with Windows hosts.
- name: Fetch attachment from remote host
win_get_url:
url: "scp://{{ inventory_hostname }}:/path/to/attachment"
dest: /local/path
Please note that you need to have the necessary permissions and credentials to access the remote host and retrieve the attachment.