{"id":3723,"date":"2018-02-25T13:02:21","date_gmt":"2018-02-25T12:02:21","guid":{"rendered":"https:\/\/www.devco.net\/?p=3723"},"modified":"2018-02-25T13:02:33","modified_gmt":"2018-02-25T12:02:33","slug":"choria-playbooks-dsl","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2018\/02\/25\/choria-playbooks-dsl.php","title":{"rendered":"Choria Playbooks DSL"},"content":{"rendered":"
I previously wrote about Choria Playbooks<\/a> – a reminder they are playbooks written in YAML format and can orchestrate many different kinds of tasks, data, inputs and discovery systems – not exclusively ones from MCollective. It integrates with tools like terraform, consul, etcd, Slack, Graphite, Webhooks, Shell scripts, Puppet PQL and of course MCollective.<\/p>\n I mentioned in that blog post that I did not think a YAML based playbook is the way to go.<\/p>\n I am very pleased to announce that with the release of Choria 0.6.0 playbooks can now be written with the Puppet DSL. I am so pleased with this that effectively immediately the YAML DSL is deprecated and set for a rather short life time.<\/p>\n A basic example can be seen here, it will:<\/p>\n As you can see we can re-use playbooks and build up a nice cache of utilities that the entire team can use, the support for locks and data sharing ensures safe and coordinated use of this style of system.<\/p>\n You can get this today if you use Puppet 5.4.0 and Choria 0.6.0. Refer to the Playbook Docs<\/a> for more details, especially the Tips and Patterns section<\/a>.<\/p>\n The Plan DSL as you’ll see in the Background and History<\/em> part later in this post is something I have wanted a long time. I think the current generation Puppet DSL is fantastic and really suited to this problem. Of course having this in the Plan DSL I can now also create Ruby versions of this and I might well do that.<\/p>\n The Plan DSL though have many advantages:<\/p>\n I could not compete with this in any language I might want to support.<\/p>\n As I mentioned the YAML playbooks are not long for this world. I think they were an awesome experiment and I learned a ton from them, but these Plan based Playbooks are such a massive step forward that I just can’t see the YAML ones serving any purpose what so ever. <\/p>\n This release supports both YAML and Plan based Playbooks, the next release will ditch the YAML ones. <\/p>\n At that time a LOT of code will be removed from the repositories and I will be able to very significantly simplify the supporting code. My goal is to make it possible to add new task types, data sources, discovery sources etc really easily, perhaps even via Puppet modules so the eco system around these will grow.<\/p>\n I will be doing a bunch of work on the Choria Plugins (agent, server, puppet etc) and these might start shipping small Playbooks that you can use in your own Playbooks. The one that started this blog post would be a great candidate to supply as part of the Choria suite and I’d like to do that for this and many other plugins.<\/p>\n For many years I have wanted Puppet to move in a direction that might one day support scripts – perhaps even become a good candidate for shell scripts, not at the expense of the CM DSL but as a way to reward people for knowing the Puppet Language. I wanted this for many reasons but a major one was because I wanted to use it as a DSL to write orchestration scripts for MCollective.<\/p>\n I did some proof of concepts of this late in 2012, you can see the fruits of this POC here<\/a>, it allowed one to orchestrate MCollective tasks using Puppet DSL<\/a> and a Ruby DSL<\/a>. This was interesting but the DSL as it was then was no good for this.<\/p>\n\n
\r\n# Disables Puppet and Wait for all in-progress catalog compiles to end\r\nplan acme::disable_puppet_and_wait (\r\n Enum[alpha, bravo] $cluster\r\n) {\r\n choria::run_playbook(acme::slack_notify, message => \"Disabling Puppet in cluster ${cluster}\")\r\n\r\n $puppet_agents = choria::discover(\"mcollective\",\r\n discovery_method => \"choria\",\r\n agents => [\"puppet\"],\r\n facts => [\"cluster=${cluster}\"],\r\n uses => { puppet => \">= 1.13.1\" }\r\n )\r\n\r\n $ds = {\r\n \"type\" => \"consul\",\r\n \"timeout\" => 120,\r\n \"ttl\" => 60\r\n }\r\n\r\n choria::lock(\"locks\/puppet.critical\", $ds) || {\r\n choria::task(\r\n \"action\" => \"puppet.disable\",\r\n \"nodes\" => $puppet_agents,\r\n \"fail_ok\" => true,\r\n \"silent\" => true,\r\n \"properties\" => {\"message\" => \"restarting puppet server\"}\r\n )\r\n\r\n choria::task(\r\n \"action\" => \"puppet.status\",\r\n \"nodes\" => $puppet_agents,\r\n \"assert\" => \"idling=true\",\r\n \"tries\" => 10,\r\n \"silent\" => true,\r\n \"try_sleep\" => 20,\r\n )\r\n }\r\n\r\n choria::run_playbook(acme::slack_notify,\r\n message => sprintf(\"Puppet disabled on %d nodes in cluster %s\", $puppet_agents.count, $cluster)\r\n )\r\n}\r\n<\/pre>\n
Why Puppet based DSL?<\/H2><\/p>\n
\n
Future of Choria Playbooks<\/H2><\/p>\n
Background and History<\/H2><\/p>\n