0
votes

In my salt state files I have several occurrences of a pattern which consists of defining a remote repository and importing a gpg key file definition, e.g.

import_packman_gpg_key:
    cmd.run:
        - name: rpm --import http://packman.inode.at/gpg-pubkey-1abd1afb.asc
        - unless: rpm -q gpg-pubkey-1abd1afb-54176598

packman-essentials:
    pkgrepo.managed:
        - baseurl: http://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_Tumbleweed/Essentials/
        - humanname: Packman (Essentials)
        - refresh: 1
    require:
        - cmd: import_packman_gpg_keygpg-pubkey-1abd1afb-54176598

I would like to abstract these away as a different state, e.g.

packman-essentials:
    repo_with_key.managed:
        - gpg_key_id: 1abd1afb-54176598
        - gpg_key_src: http://packman.inode.at/gpg-pubkey-1abd1afb.asc
        - repo_url: http://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_Tumbleweed/Essentials/
        - repo_name: Packman (Essentials)

which will in turn expand to the initial declarations above. I've looked into custom salt states ( see https://docs.saltstack.com/en/latest/ref/states/writing.html#example-state-module ) but I only found references on how to create one using Python. I'm looking for one which is based only on state definitions, as writing code for my specific problem looks overkill.

How can I create a custom state which reuses the template I've been using to manage package repositories?

1

1 Answers

1
votes

This is what macros are for

Here is an example of simple macros for some heavily used by me constructs

However in your example, why do you cmd.run to import key?
pkgrepo.managed seems to support gpgkey option to download the key