自动化操作:如何执行食谱



我正在使用awscli尝试自动化部署过程(将食谱更改上传到s3,单击stuff更新食谱,单击stuff运行recipie,键入我要执行的食谱的名称)。

我真的很接近,但我找不到任何关于如何通过awscli在opsworks中实际执行给定配方的信息。我想它一定非常接近于更新定制食谱:

$ aws opsworks create-deployment --command "{"Name":"update_custom_cookbooks"}"  --stack-id xxxxx --instance-ids xxxxxxxxx
xxxxxxxx #deployment id

文档中没有告诉我"execute_procipes"命令的格式:http://docs.aws.amazon.com/cli/latest/reference/opsworks/create-deployment.html

在发送了一堆猜测并使用了极具洞察力的"无效值"、SerializationException和ValidationException之后,我推断出以下内容可能接近我想要的:

$ aws opsworks create-deployment --command "{"Name":"execute_recipes", "Args":{"Recipes":["book::recipe"]}}"  --stack-id xxxxxx --instance-ids xxxxxxxx                                                                                                                                 
A client error (ValidationException) occurred

让Opsworks在给定实例上执行配方的正确JSON模式是什么?

编辑:修复示例,添加解释

awscli元数据非常精细,大小写很重要。您只需将命名参数"Recipes"更改为"Recipes",您的命令就会向AWS发送一个新的部署命令。

aws opsworks create-deployment --stack-id xxxx --command '{ "Name": "execute_recipes", "Args": {"recipes": ["book:rec"]}}' --instance-ids xxxx

附加讨论:https://forums.aws.amazon.com/thread.jspa?messageID=469835&469835

由于在使用vanilla aws-cli时执行OpsWorks有点冗长,我提出了一个包装脚本,它运行得很好,尤其是在创建OpsWorks食谱的cron作业时。省去了使用堆栈id、opsworks实例id等进行查找的繁琐任务。

https://github.com/ardeearam/opsworks_local

# Run custom recipe to current instance
$ ruby opsworks_local.rb -r mycookbook::jump_high
# Deploy all applications to current instance
$ ruby opsworks_local.rb -c deploy
# Invoke deploy on another server instance
$ ruby opsworks_local.rb -c deploy -i i-7f9811b1
# Update custom cookbook
$ ruby opsworks_local.rb -c update_custom_cookbooks

最新更新