I'm trying to write a custom SaltStack state. It will be used like this:
Example of my.state usage:
my.state:
- name: /some/path
- source: salt://path/to/dsl/file
This state is planned to grab a file
from the Salt Master file server, transfer it to the minion, then execute the file using a program in the minion, analyze the output, delete the downloaded file
, and return a proper state dict based on success/failure of the program that executes the DSL file.
My question:
- How to write the custom state so it's able to download from
salt://
URI ?
Note: I do not envision the need to download the file from anywhere else but the Salt Master.
Edit: In the interest of full disclosure of facts, "success/failure" is gleaned by analyzing the output of the program, not a simple exitcode analysis. Just FYI.
I'm trying to write a custom SaltStack state. It will be used like this:
Example of my.state usage:
my.state:
- name: /some/path
- source: salt://path/to/dsl/file
This state is planned to grab a file
from the Salt Master file server, transfer it to the minion, then execute the file using a program in the minion, analyze the output, delete the downloaded file
, and return a proper state dict based on success/failure of the program that executes the DSL file.
My question:
- How to write the custom state so it's able to download from
salt://
URI ?
Note: I do not envision the need to download the file from anywhere else but the Salt Master.
Edit: In the interest of full disclosure of facts, "success/failure" is gleaned by analyzing the output of the program, not a simple exitcode analysis. Just FYI.
Share Improve this question edited Mar 31 at 7:52 pepoluan asked Mar 26 at 8:23 pepoluanpepoluan 6,9055 gold badges51 silver badges85 bronze badges 2 |1 Answer
Reset to default 1The cp
module is in charge of fetching files, as opposed to file
, which is for managing local files.
As you only want the file for working on intermediately, you'll want something like this:
file_path = __salt__["cp.cache_file"](source)
output = __salt__["cmd.run_stdout"](f"the-program '{source}'")
cp
module >,< ... I'm getting old lol. Thanks! – pepoluan Commented Mar 28 at 9:48