I'm currently working on extending some SaltStack-based automation. I'd initially written it to work on (RHEL) Linux-based hosts. Worked like a champ. I was recently asked to extend the automation to also work on Windows. My most recent "Why I hate Powershell" posts are related to other tasks around this recent request.
At any rate, the approach I've been taking to extending my SaltStack logic is to refactor the Linux logic so as to insert an execution-branch based on the detected "kernel" (what's returned when one does a `salt-call --local grains.get kernel`). Basically, I took my prior "install.sls" file and moved it to "lin_install.sls" and then made a new "install.sls" that looked like:
include:
{%- if grains.kernel == "Linux" %}
- .lin_install
{%- elif grains.kernel == "Windows" %}
- .win_install
{%- endif %}
Worked like a champ on Linux; on Windows, "not so much". So, I started debugging the logic.
I primarily write my code on Linux-based development-VMs. I'd chosen the "kernel" SaltStack-grain, as my branching-basis, because I was hoping to head off having to do compound if blocks (in case anyone ever asked, "can you make this support Ubuntu instead of just Enterprise Linux and Windows"). Otherwise, I'd have chosen the "os_family" SaltStack-grain. Prior to running the extended logic on a Windows-based host (Server 2022 for this exercise), I'd simply assumed that the code would work. Imagine my surprise when I executed it on a Server 2022-based EC2 and I was getting error messages that I should only have seen on a missconfigured Linux-based host.
First thing I did was test how saltstack was rendering my new "install.sls" file. I executed:
& 'C:\Program Files\Salt Project\Salt\salt-call.exe' -c C:\<config_path> \ slsutil.renderer C:<state_file_path>\install.sls
Interestingly, it returned
local:
----------
include:
- .win_install
This meant that the Jinja was returning the expected list-element for the include statement. So, why the hell was I getting errors as though the ".lin_install" logic were what was being executed??
Did some digging around. One of the search results I got back indicated that the SaltStack minion for Windows can be flaky when using relative pathing to invoke other SaltStack files. So, I updated my "install.sls" to look like:
include:
{%- if grains.kernel == "Linux" %}
- <formula_root>.package.lin_install
{%- elif grains.kernel == "Windows" %}
- <formula_root>.package..win_install
{%- endif %}
This time, when I executed `<formula_root>.package.install`, directly (on my Server 2022-based EC2), it worked like it always should have. The reason I don't know who to blame is that while the problem is in SaltStack, I can't help but think that the problem is resultant of Windows weirdness.
Oh well, at least I have a path forward.
No comments:
Post a Comment