最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - SaltStack custom state: How to download file from "salt:" URI - Stack Overflow

programmeradmin3浏览0评论

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 docs.saltproject.io/en/latest/ref/modules/all/… – OrangeDog Commented Mar 26 at 22:26
  • Good grief how did I miss the cp module >,< ... I'm getting old lol. Thanks! – pepoluan Commented Mar 28 at 9:48
Add a comment  | 

1 Answer 1

Reset to default 1

The 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}'")
发布评论

评论列表(0)

  1. 暂无评论