如何从 orchestrate 运行ner 在 salt orchestrator 上 运行 本地命令

How to run local commands on the salt orchestrator from the orchestrate runner

我正在尝试在 salt orchestrator 上执行 redis-trib.rb 实用程序(用于配置 redis 集群),然后在多个 minions 上执行 salt 状态以启动 redis 进程。

阅读 salt 文档,看起来 orchestrate runner 做了我想执行的 minion 状态。

确实,当使用 sudo salt-run state.orchestrate orch.redis_cluster:

执行时,此代码段功能完美
redis_cluster_instances_create:
  salt.state:
    - tgt: '*redis*'
    - highstate: True

问题在于下一步,这需要我在协调器上调用 redis-trib.rb。阅读文档看起来我需要使用 salt.runner 状态(执行另一个跑步者),调用 salt.cmd 跑步者(在本地执行盐状态),后者又调用 cmd.run 实际执行命令的状态。

我得到的是这样的:

redis_cluster_setup_masters_{{ cluster }}:
  salt.runner:
    - name: salt.cmd
    - fun: cmd.run
    - args:
      - srv/salt/orch/redis_cluster/usr/bin/redis-trib.rb create {% for shard in shards %}{{ shard['master'] }} {% endfor %}
    - kwargs:
      unless: srv/salt/orch/redis_cluster/usr/bin/redis-trib.rb info {{ shards[0]['master'] }} | grep 'cluster_state:ok'
    - require:
      - salt: redis_cluster_instances_create

但它不起作用,盐错误如下:

lab-orchestrator_master:
----------
          ID: redis_cluster_instances_create
    Function: salt.state
      Result: True
     Comment: States ran successfully. No changes made to lab-redis04, lab-redis01, lab-redis02, lab-redis03.
     Started: 09:54:57.811313
    Duration: 14223.204 ms
     Changes:   
----------
          ID: redis_cluster_setup_masters_pdnocg
    Function: salt.runner
        Name: salt.cmd
      Result: False
     Comment: Exception occurred in runner salt.cmd: Traceback (most recent call last):
                File "/usr/lib/python2.7/site-packages/salt/client/mixins.py", line 392, in _low
                  data['return'] = self.functions[fun](*args, **kwargs)
              TypeError: cmd() takes at least 1 argument (0 given)
     Started: 09:55:12.034716
    Duration: 1668.345 ms
     Changes:   

谁能指出我做错了什么?或者在协调器上本地执行命令的替代方法?

问题是,您正在通过 fun 等。阿尔。到跑步者而不是执行模块。另请注意,您必须通过 arg 而不是 args:

传递参数
redis_cluster_setup_masters_{{ cluster }}:
  salt.runner:
    - name: salt.cmd
    - arg:
      - fun=cmd.run
      - cmd='srv/salt/orch/redis_cluster/usr/bin/redis-trib.rb create {% for shard in shards %}{{ shard['master'] }} {% endfor %}'
    - unless: srv/salt/orch/redis_cluster/usr/bin/redis-trib.rb info {{ shards[0]['master'] }} | grep 'cluster_state:ok'
    - require:
      - salt: redis_cluster_instances_create

虽然我还没有使用 kwargs 参数对其进行测试,但应该可以解决问题。