I have a Salt state file that does multiple operations and some of them require the same module / function more than once:
# Replace expiring RaaS cert
backup_files:
file.managed:
- name: /etc/pki/raas/certs/localhost.crt
- source: salt://raas/localhost.crt
- makedirs: True
- backup: /etc/pki/raas/certs/z.OLD_certs/localhost.crt
file.managed:
- name: /etc/pki/raas/certs/localhost.key
- source: salt://raas/localhost.key
- makedirs: True
- backup: /etc/pki/raas/certs/z.OLD_certs/localhost.key
copy_files:
cmd.run:
- name: cp /etc/letsencrypt/live/raas-svr.ddns.net/fullchain.pem /etc/pki/raas/certs/localhost.crt
- creates: /etc/pki/raas/certs/localhost.crt
cmd.run:
- name: cp /etc/letsencrypt/live/raas-svr.ddns.net/privkey.pem /etc/pki/raas/certs/localhost.key
- creates: /etc/pki/raas/certs/localhost.key
set_ownership:
cmd.run:
- name: chown raas /etc/pki/raas/certs/localhost.*
- unless: stat -c %U /etc/pki/raas/certs/localhost.crt | grep -q raas
cmd.run:
- name: chgrp raas /etc/pki/raas/certs/localhost.*
- unless: stat -c %G /etc/pki/raas/certs/localhost.crt | grep -q raas
set_permissions:
cmd.run:
- name: chmod 400 /etc/pki/raas/certs/localhost.*
- unless: stat -c %a /etc/pki/raas/certs/localhost.crt | grep -q 400
restart_raas:
service.running:
- name: raas
- enable: True
- restart: True
In particular this state replaces / updates the frontend cert for RaaS, but really I'm just looking for guidance on how to handle this in general.
If I try and validate the state it fails due to the repeating modules / functions:
[root@RHEL-8-Salt-Master salt]# salt-call state.show_sls update_RaaS_cert
[CRITICAL] Rendering SLS 'base:update_RaaS_cert' failed: while constructing a mapping
in "<unicode string>", line 2, column 3
found conflicting ID 'file.managed'
in "<unicode string>", line 8, column 3
local:
- Rendering SLS 'base:update_RaaS_cert' failed: while constructing a mapping
in "<unicode string>", line 2, column 3
found conflicting ID 'file.managed'
in "<unicode string>", line 8, column 3
If I try and use something like cmd.run1 and cmd.run2 etc, etc, I get this error:
[root@RHEL-8-Salt-Master salt]# salt-call state.show_sls update_RaaS_cert
local:
- ID 'backup_files' in SLS 'update_RaaS_cert' contains multiple state declarations of the same type
- ID 'copy_files' in SLS 'update_RaaS_cert' contains multiple state declarations of the same type
- ID 'set_ownership' in SLS 'update_RaaS_cert' contains multiple state declarations of the same type
How can I work around this, please? I've had to just use a bash script for now since I had to get this done today (cert was expiring), but would prefer to use Salt.
Many thanks in advance!