salt-project

Salt script local copy multiple files from one dir to another


I wanted to copy multiple files (file names and number of files are dynamic) from one dir to another locally within a minion. Expecting equivalent of below.

cp /app/downloaded/*.* /app/myapp/installables/.

Destination dir already exists. Previous version files are required to be retained at the destination and so I cannot delete destination dir or the existing files there.

I think I am missing something simple. Please can anyone help.

Tried the below

Copy_new_version_files_for_installation:
  file.copy:
    - name: /app/myapp/installables
    - source: /app/downloaded
    - recurse: True

but getting

          ID: Copy_new_version_files_for_installation
    Function: file.copy
        Name: /app/myapp/installables
      Result: True
     Comment: The target file "/app/myapp/installables" exists and will not be overwritten


Solution

  • Looks like this is a confusion between the execution module and state module.

    To use execution module from within state (SLS) files, we need to specify module.run. Otherwise Saltstack will try to run the file.copy state.

    Below example should work:

    Copy_new_version_files_for_installation:
      module.run:
      - file.copy:
        - dst: /app/myapp/installables
        - src: /app/downloaded
        - recurse: True