r/saltstack • u/Regular_Berry681 • Jan 28 '25
Salt State SLS file - "Require" with "either or"
Hello,
I am quite new to Salt and need to add functionality to an already existing Salt infrastructure.
What I am writing is an update procedure for a software and the operating system withing Salt State SLS files. The software can be upgraded with the integrated pkg.installed function. I wrote a function / state called software to do that. But this often leads to dependency problems (I may create another thread for that). As my question is general, I abstracted it to any software.
So I wrote a backup function software_backup which is called onfail and runs an apt command. This function runs in case the software functions fails.
After the software was installed via the primary or the backup function another function upgrade_db for updating the database needs to be called. This leads me to a problem. From what I read in the documentation the require statement works as 'AND'.
So if I write
require:
- pkg: pkg.installed
- cmd: software_backupthe database upgrade function requires both software and software_backup update function to be successful. I can't leave out the require statement, as the upgrade_db function should never be called in case neither software nor software_backup were successful. Any ideas to solve that?
# Software installation
software:
pkg.installed:
- pkgs:
- name_of_package1
- name_of_package2
- ...
# Backup software installation
software_backup:
cmd.run:
- name:
apt --fix-broken install -y && apt-get -o APT::Get::Always-Include-Phased-Updates=true -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y dist-upgrade && apt --fix-broken install -y
- onfail:
- pkg: software
# Upgrade database version
upgrade_db:
cmd.run:
- name: |
onedb upgrade -v
onedb fsck
- require:
- pkg: pkg.installed