This is a sample of how my top file looks
base:
'*':
- sls_file_1
- sls_file_2
'smtp*':
- sls_file_3
- sls_file_4
sls_file_1
& sls_file_2
are expected to run on all minions while sls_file_3
& sls_file_4
only on minions with hostname starting with smtp.
When I run the highstate on a host whose hostname starts with smtp,
Only '*'
part of the top file is executed and not the 'smtp*'
on the first try (First time after host is up and running). You might say maybe the hostname is not set at that point in time, thats why it is not executed, but I have a ExecStartPre
set in the salt-minon service file which sets the hostname before the salt-minon starts up
~ ❯ cat /usr/lib/systemd/system/salt-minion.service
[Unit]
Description=The Salt Minion
Documentation=man:salt-minion(1) file:///usr/share/doc/salt/html/contents.html https://docs.saltstack.com/en/latest/contents.html
After=network.target salt-master.service
[Service]
KillMode=process
Type=notify
NotifyAccess=all
LimitNOFILE=8192
ExecStartPre=/etc/salt/add_minion_id.sh
ExecStart=/usr/bin/salt-minion
[Install]
WantedBy=multi-user.target
Contents of add_minion_id.sh
(Sets the hostname)
~ ❯ cat /etc/salt/add_minion_id.sh
#!/usr/bin/env bash
udata=`curl -s http://169.254.169.254/latest/user-data`
if [[ ! $udata == \#* ]]
then
new_hostname=`echo $udata| cut -d , -f1| cut -d : -f2`
else
new_hostname=`cat /etc/salt/userdata | cut -d , -f1| cut -d : -f2`
fi
hostname $new_hostname
echo $new_hostname > /etc/salt/minion_id
echo $new_hostname > /etc/hostname
So my expectation is all the 4 files in the top file will be executed since the hostname is set at that point, but that is not the case. Is there something I am missing?