How do I call archive.tar in salt?
-
26-12-2019 - |
Question
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
OTHER TIPS
Actually: The states.archive is completely missing from the 0.17.x tarballs!
markizano@localhost:/tmp/salt$for tar in *; do tar --list -f $tar; done|sort|grep archive.py
salt-0.16.0/salt/modules/archive.py
salt-0.17.0/salt/modules/archive.py
salt-0.17.1/salt/modules/archive.py
salt-0.17.2/salt/modules/archive.py
salt-0.17.3/salt/modules/archive.py
salt-0.17.4/salt/modules/archive.py
salt-0.17.5/salt/modules/archive.py
salt-2014.1.0/salt/modules/archive.py
salt-2014.1.0/salt/states/archive.py
Upgrade to the latest version to have access to archive.extracted in your states.
As a hotfix, you can copy the develop branch of the github into
{{ salt['grains.get']('saltpath') }}/states/archive.py
Restart saltmaster/saltminion after an update like this.
SaltDocs: http://docs.saltstack.com/ref/states/all/salt.states.archive.html
If you're seeing this message, and you're working with a windows minion, and the release you're using is earlier than 2015.2, it's telling the truth. It's not available. See https://github.com/saltstack/salt/issues/12992.