3 ms·
I am starting with Ansible and pretty much my first thought was to write my own "super" python scripts that called Ansibke instead of using playbook and their D
by lifeisstillgood 11y ago
I am starting with Ansible and pretty much my first thought was to write my own "super" python scripts that called Ansibke instead of using playbook and their DSL
But, is this a good idea? As the first six comments here are starting that discussion, what are the pros and cons?
The API may be rich but it feels a second class citizen. But DSLs are really hard to get right and often lack ... Everything.
- loevborg 11y agoI would encourage you to start by learning Ansible's yaml syntax, which really goes a long way and which represents a lot of best practices in the devops world, such as immutability, configurability and config file templating. I have yet to run into a situation where I had to reach for python, calling the API directly or even extending ansible itself. However, sometimes you may want to mix local actions (say, spin up ec2 instances) and remote actions (provision said ec2 instances). In these cases, a simple wrapper bash or python script to combine these has proven helpful.
- fideloper 11y agoThis has been my use case. We spin up a lot of trial servers on aws for customers, each with some unique data. I've written Python to call Ansible (1.9) programmatically, which was a fun challenge, even if possibly more work than was needed: https://serversforhackers.com/running-ansible-programmatically https://serversforhackers.com/running-ansible-programmatical... Ansible 2 changes a lot of that, so a followup for how-to in Ansible 2 is in order eventually.
- href 11y agoWe wrote our own Api wrapper to run Ansible commands on our infrastructure. It aims to encapsulate all the complicated bits. Maybe this is of interest to you: https://github.com/seantis/suitable https://github.com/seantis/suitable We use Puppet mainly, but depend on Ansible for updates, migrations and other things where we want to control the transition, not just the end state.
- senorsmile 11y agoThis is actually pretty neat. Thanks for posting.
- fideloper 11y agoThanks, I'll definitely give that a look!
- akurilin 11y agoWe use a super script that calls ansible. We have multiple AWS accounts and multiple environments within them and it's tricky to avoid repetition of configuration without an external tool. I see it as a good practice. The different cascading layers of variables can be hard to reason about, but it does lead to a good amount of DRY.