I have to agree with Brian – sounds like you are not breaking your problem down into simple enough parts.
The problem with Ansible (and other similar config management / state management tools) is that most people (well, at least me) come in thinking one way about their requirements which isn’t immediately compatible with how the tool was designed and/or works. You have to learn to think about your problems in terms of Ansible (or whatever tool you’re using).
In this case, Ansible is stupidly simple on purpose. However, I’ve been beating my head against it for about 6 months now and am just starting to really ‘get it’. And most of that was me learning how to simplify what I needed to do into smaller and smaller chunks which made sense for Ansible and then how to relate those chunks together.
One of the big things was determining when and where I did certain things within Ansible. You can put things in playbooks or roles or both, but not all will necessarily be good for you. For example I have a role for my NTP configuration. I then have this role applied to all hosts in my top level play list. However, I then ran into a hurdle as all machines need NTP, but there is one machine that must be an NTP server. I first worked on this with having different roles (ntp-client vs ntp-server) but found for my needs that a single ‘ntp’ role would suffice and within that role I then choose one of two different templates (client vs server) based upon whether or not the host was in the ‘ntp server‘ host group. I do want to point out that I could have used two different roles but I decided against that for reasons that make sense within my hosting environment. My point is, I had many options on how to put the Ansible building blocks together and it took me a while to figure out the best way to put them together for my needs. There was a lot of trial and error. But I’ve finally got there.
Another thing I did was to use the ‘group_by’ functionality to build host groups on the fly. Then I use those groupings to determine when to apply different roles or even different parts of specific roles. So, originally I just had roles with a single ‘tasks/main.yml’. And I tried to keep it that way. But after working with Ansible for a while and reviewing what I was trying to do, I now have roles with lots of task files that get included within tasks/main.yml. So a lot of my roles use a lot of ‘include/when’ patterns based around groupings I’ve built on the fly via ‘group_by’.
So, TL;DR – keep pounding on it, keep trying different code arrangements, keep trying to break your requirements into smaller and simpler parts. Also, you have to figure out how best to put all the pieces together. Such as some people don’t use role dependencies, but some people love them. Eventually you’ll get it. And I would say that as you use Ansible expect that you will end up re-writing your entire Ansible code base a couple of times until you find a layout that works best for you.
Thx
Gopher.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
ansible-proje...@googlegroups.com.
To post to this group, send email to
ansible...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CADn%2BHsyF_rJST5VOmc4xSUg9As86Ls3iWnhAa2f_t4CEXLGSxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
In my mind, any particular role that a server may fill (and it may fill more than one), in turn requires one or more "features" or "feature-sets" in order to be able to fulfill that role. In other words, I think of a heirarchy that looks like this;
* appstack_X
** server_n
*** role_a
**** feature_A
**** feature_E
**** feature_O
*** role_b
**** feature_A
**** feature_B
**** feature_G
Anyone else gone through this thought process,or organize their configs like this?
Yes. I'm only new to ansible but am seriously struggling. The playbooks I can get my head around but the roles are proving very painful. I thought the idea might be to switch features on/off for each host via variables? Would that work?
[Trivial annoyance: i hate the way it requires a bunch of folders with just one file in them each]
[Related to that sidenote: the folders are going to have lonely main.ymls for quite a while since the only apparent use of a file in the same directory is to be 'included' from main.yml? Have I got that wrong?]
On Tuesday, June 3, 2014 2:38:45 PM UTC+10, David Carmean wrote:
I was happy to see "roles" when I came back to Ansible after a few months, but i've been struggling with how to apply them. I think this is partly because of cognitive dissonance between my mental model and the current terminology.
In my mind, any particular role that a server may fill (and it may fill more than one), in turn requires one or more "features" or "feature-sets" in order to be able to fulfill that role. In other words, I think of a heirarchy that looks like this;
* appstack_X
** server_n
*** role_a
**** feature_A
**** feature_E
**** feature_O
*** role_b
**** feature_A
**** feature_B
**** feature_G
Anyone else gone through this thought process,or organize their configs like this?
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fe22dca9-a01c-4afc-afea-7cf5acbc84e2%40googlegroups.com.
Both profiles and states are roles, but I separate them into two roles directories. I then use role dependencies between profiles and states (and states and states). A playbook simply ties hosts to profile roles.
A few thing I ran into:
* I needed to use a trick to make sure each state role is run only once. See [1].
And so on, its very simple and its easy to manager :-)