Search code examples
tarsalt-project

How do I call archive.tar in salt?


I'm trying to untar a file in a salt state file. This is the relevant state:

install-file:
#unpack
  archive.tar:
    - options: xjf
    - tarfile: /opt/path/to/file.tar.bz
    - dest: /opt/path/to/
    - watch:
      - file: /opt/path/to/file.tar.bz
#get files
  file.managed:
    - source: salt://pkgs/path/to/file.tar.bz
    - name: /opt/path/to/file.tar.bz

But I keep getting the following error:

    State: - archive
    Name:      install-sdk
    Function:  tar
        Result:    False
        Comment:   State archive.tar found in sls pkgs.android is unavailable

Any idea what I'm doing wrong? I'm pretty sure it's not a versioning issue.


Solution

  • The main issue here is that there is no archive.tar state. The reason for that is probably misunderstanding of so-called modules and states. The archive is module with some functions you can call from cli like:

    salt '*' archive.tar cjvf /tmp/tarfile.tar.bz2 /tmp/file_1,/tmp/file_2
    

    Now there is a way to actually use the module from your states. There is a module.run state to do just that. I made a quick example with the archive.tar call:

    untar_file:
      module.run:
        - name: archive.tar
        - options: xjf
        - tarfile: /opt/path/to/file.tar.bz 
        - dest: /opt/path/to/
    

    The -name parameter specifies which module and function to run, the other parameters are passed to the actual function.

    You can find additional parameters that are passed to the tar function here: http://docs.saltstack.com/ref/modules/all/salt.modules.archive.html#salt.modules.archive.tar