Copying asset files to a remote machine when running a module

I am developing a module that generates a port.conf file for mellanox/nvidia switches running cumulus linux.

My module compares specified configuration with a template file that is specific to a model and contains all possible modes for each interface of that device. For example, sometimes enabling a port with a certain network speed necessarily disables another port, usually the adjacent port.

---
# Example of how i want to use my module.
# default port configuration is 1x100Gbit
# port1 is broken out to 4x10Gbit
# port2 is broken out to 2x50Gbit
- name: Test generate_ports_conf
  surf.cumulus.generate_ports_conf:
    default:
      breakout: 1
      speed: 100
    ports:
      - port: 1
        breakout: 4
        speed: 10
      - port: 2
        breakout: 2
        speed: 50
# Example snippet of a template file that i compare against
# port1 in the mode speed=10 and breakout=4 disables port2
---
name: msn4600
ports:
  port1:
    type: qsfp56
    modes:
      - speed: 1
        breakout: 4
        disables:
          - port2
      - speed: 10
        breakout: 4
        disables:
          - port2
      ...

While testing on remote machines i noticed that those yaml files containing the templates are not copied to the remote host, so naturally the module fails. I have not found any modules in the wild that copy assets to the remote machines.

How can i make ansible copy these files to the remote machines? They should accompany the rest of the module so that they are automatically cleaned up after the task is done.

you need an action plugin, script is one example that copies a file to the target, runs it and deletes it. Also see the template for another example, it uses the copy action once it generates the template on the controller to get it to the target

Thanks, that looks viable indeed. I will report back next week with the results once i’ve implemented this. I had no clue that this is what action plugins are for.