0

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?

  • 2
    How/when are the minions added to Salt master? We can check which minions are actually available using `salt-run manage.up`, or even `salt-key -L` to see if the minions actually joined the master. – seshadri_c Oct 19 '21 at 10:26
  • 1
    for this to be honestly answered you are going to need to do a bit of troubleshooting. you say the first two run so what you should do is add a third state to the `'*'` list that adds a test state that outputs the `grains['id']` value. it is possible that the minion is already started before your `ExecStartPre` is added to the service. might also help to look at the user data. – whytewolf Oct 19 '21 at 16:13
  • `salt \* test.ping` would also be relevant output. – Wayne Werner Jan 06 '22 at 23:43

0 Answers0