【问题标题】:Saltstack running a bash script through cmd.script via rest_cherrypy with multiple argsSaltstack通过带有多个参数的rest_cherrypy通过cmd.script运行bash脚本
【发布时间】:2020-03-06 16:44:04
【问题描述】:

尝试使用 rest_cherrypy 在 minion 上运行 bash 脚本。脚本需要多个参数。在以下示例中,它适用于一个参数:

 resp = session.post('https://192.168.50.10:8000/', json=[{    
      'client': 'local',                                        
      'tgt': 'minion1',                                         
      'fun': 'cmd.script',                                      
      'arg': ['salt://scripts/my_script.sh', 'arg1'],           
  }])                                                           
  return resp.json()    

输出:{'return': [{'minion1': {'pid': 2836, 'retcode': 0, 'stderr': '', 'stdout': 'arg1'}}]}

但是尝试使用多个参数给了我这个:

 resp = session.post('https://192.168.50.10:8000/', json=[{
        'client': 'local',
        'tgt': 'minion1',
        'fun': 'cmd.script',
        'arg': ['salt://scripts/my_script.sh', ('arg1', 'arg2')],
    }])
    return resp.json()

输出:

{'return': [{'minion1': {'pid': 2808, 'retcode': 0, 'stderr': '', 'stdout': '[uarg1,'}}]}

通过rest_cherrypy将多个参数传递给cmd.script函数的正确方法是什么?

【问题讨论】:

    标签: salt-stack


    【解决方案1】:

    设法以这种方式解决它:

        resp = session.post('https://192.168.50.10:8000/', json=[{                                                        
         'client': 'local',                                                                                            
         'tgt': 'minion1',                                                                                             
         'fun': 'cmd.script',                                                                                          
         'arg': ['salt://scripts/my_script.sh', """ {}, {}, {}, {} """.format(mail_from, mail_to, date_from, date_to)],
     }])      
    

    【讨论】:

      猜你喜欢
      • 2011-01-23
      • 2020-11-10
      • 1970-01-01
      • 2015-02-28
      • 2020-08-18
      • 2021-03-20
      • 2016-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多