Reputation: 1990
I'm only a beginner with SaltStack. I can see there is a pkgrepo module that can be used to set up a package repo in order to install a package from it.
https://docs.saltstack.com/en/latest/ref/states/all/salt.states.pkgrepo.html
An example given there is:
base:
pkgrepo.managed:
- humanname: Google Chrome
- name: deb http://dl.google.com/linux/chrome/deb/ stable main
- dist: stable
- file: /etc/apt/sources.list.d/chrome-browser.list
- require_in:
- pkg: google-chrome-stable
- gpgcheck: 1
- key_url: https://dl-ssl.google.com/linux/linux_signing_key.pub
What I do not understand is where do I put the above code? I tried in the /srv/salt/top.sls, and in other state .sls files there, but that is not right. How is it done?
Upvotes: 3
Views: 8370
Reputation: 945
You basically want to know how to use SaltStack states. This is documented at https://docs.saltstack.com/en/latest/topics/tutorials/starting_states.html.
To test this code, you have to:
testrepo.sls
salt
command.Example:
salt 'hostname.domainname' state.sls testrepo
where hostname.domainname
is the name of the minion
(saltstack client) you wish to configure, as reported by salt-key
.
In the given examples, base
is the state name. It must be unique. So base
was a very bad choice to use in the docs, as it may confuse you with the top sls files syntax, documented here: https://docs.saltstack.com/en/latest/ref/states/top.html
So, in order to install google-chrome, to take your example, you'd create a state file like the following:
google_chrome_repository:
pkgrepo.managed:
- humanname: Google Chrome
- name: deb http://dl.google.com/linux/chrome/deb/ stable main
- dist: stable
- file: /etc/apt/sources.list.d/chrome-browser.list
- gpgcheck: 1
- key_url: https://dl-ssl.google.com/linux/linux_signing_key.pub
google-chrome-stable:
pkg.installed:
- require:
- pkgrepo: google_chrome_repository
Note that I change the requisite declaration from a require_in
to a require
that have more sense here, in my opinion, if you have more than one package to install from this repository. Requisites are documented here: https://docs.saltstack.com/en/latest/ref/states/requisites.html
Upvotes: 12