Ansible mail attach multiple files

To attach multiple files to an email using Ansible, you can use the mail module and the attach parameter. Here's an example:

- name: Send email with multiple attachments
  mail:
    host: your_smtp_server
    port: 587
    username: your_email_username
    password: your_email_password
    from: your_email_address
    to: recipient_email_address
    subject: Multiple attachments
    body: This is a test email with multiple attachments
    attach:
      - /path/to/file1.txt
      - /path/to/file2.txt
      - /path/to/file3.txt

In this example, the attach parameter is a list of file paths that you want to attach to the email. Ansible will automatically add each file to the email as an attachment.

You can also use the attach parameter with a dictionary to specify additional options for each attachment, such as the file name and content type. For example:

- name: Send email with multiple attachments
  mail:
    host: your_smtp_server
    port: 587
    username: your_email_username
    password: your_email_password
    from: your_email_address
    to: recipient_email_address
    subject: Multiple attachments
    body: This is a test email with multiple attachments
    attach:
      - { path: /path/to/file1.txt, filename: file1.txt, content_type: text/plain }
      - { path: /path/to/file2.txt, filename: file2.txt, content_type: text/plain }
      - { path: /path/to/file3.txt, filename: file3.txt, content_type: text/plain }

In this example, each attachment is specified as a dictionary with the following keys:

You can customize these options to fit your specific use case.