saltstack variable parameters are passed to the command line file state sls

There is a demand, every time the service update release to pull a different version of Docker image to boot, here comes to a problem: how to pass the problem Docker image version number.
Saltstack online environment is released, the question becomes: how to pass parameters to the state sls variables in the file from the command line.
Variables can be passed from the command line pillar resolved.
Examples are as follows:
. 1, the startup.sh jinja variables defined in the script {{ version }}, to distinguish between different versions of the image Docker

// startup.sh 文件
#!/bin/bash
docker pull harbor.foobar.cn/prod/web-service:{{ version }} && \
docker run -d --name web-service harbor.foobar.cn/prod/web-service:{{ version }}

2, deploy.sls file a statement startup.sh use jinjia template - template: jinja, and pass variables to startup.sh file version, version variable version: {{ salt['pillar.get']('version') }}acquisition pillar variable parameters passed from the command line

// deploy.sls 文件
app-script-file:
  file.managed:
    - name: /data/apps/startup.sh
    - source: salt://releases//files/startup.sh
    - mode: 755
    - user: root
    - group: root
    - makedirs: True
    - template: jinja
    - defaults:
      version: {{ salt['pillar.get']('version') }}

3, when called salt state sls file by passing parameters in the command line pillar='{version: 版本号}'when you can achieve the update was released, pull the different versions of Docker image to boot

salt '*' state.apply deploy pillar='{version: 1.1.0}'

reference:

  1. https://stackoverflow.com/questions/17711342/salt-can-i-use-an-argument-from-the-command-line-as-a-jinja-variable

Reproduced in: https: //www.jianshu.com/p/771ed60c985c

Guess you like

Origin blog.csdn.net/weixin_34315665/article/details/91267512