Is this possible with Ansible?

119 views
Skip to first unread message

Chris Short

unread,
Feb 9, 2015, 4:19:21 PM2/9/15
to ansible...@googlegroups.com
I'm trying to wrap my brain around something. Can Ansible deploy different application configuration files based upon a hostname, IP address, network address, etc? To take that a step further, could Ansible look at a template and then fill in the blanks based upon hostname, IP, and/or network address? If so, how? Is there an example somewhere. 

I'm trying to wrap my mind around this concept still so I might not be asking this in the right way.

Thanks in advance for any feedback.

Brent Langston

unread,
Feb 9, 2015, 5:05:59 PM2/9/15
to ansible...@googlegroups.com
short answer is yes... easily.

An example of your template scenario might look something like this:

      {% if ansible_local.oscar.tags.environment == "production" %}
          server_name  foo.example.com;
      {% elif ansible_local.oscar.tags.environment == "staging"   %}
          server_name foo-staging.example.com;
      {% else %}
          server_name  {{ ansible_fqdn }};
      {% endif %}

--------
Brent
--------

--
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/3a50e90e-326a-4b24-8309-ffab6b2294f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Feb 9, 2015, 5:10:15 PM2/9/15
to ansible...@googlegroups.com
many ways to do it, another example is having a variable defined in
production/staging groups:

[production:vars]
subdomain: example.com

[staging:vars]
subdomain: -staging.example.com

...

in template:

server_name {{inventory_hostname + subdomain|default('-dev.example.com') }}

Chris Short

unread,
Feb 10, 2015, 7:51:46 AM2/10/15
to ansible...@googlegroups.com
I kinda get it? Maybe I'm not presenting this correctly or largely enough. I need to deploy multiple configuration files (dozens) across multiple environments. Configurations would likely not share many values. For example:

AppA
|_ConfigA - 7 different option/variable pairs
|_ConfigB - 4 different option/variable pairs
|_ConfigC - 12 different option/variable pairs

AppB
|_ConfigD - 2 different option/variable pairs
|_ConfigE - 17 different option/variable pairs
|_ConfigF - 24 different option/variable pairs

The list goes on and on. Also, some environments might have one option/variable pair where others have multiples (dev lab moving on up through production).

Can anyone point me to an example of this? The documentation doesn't seem to be helping me see this on a grander scale (or maybe I'm missing something).

Peter Buckley

unread,
Feb 10, 2015, 10:18:23 AM2/10/15
to ansible...@googlegroups.com
Ansible definitely supports the scenario you're describing. I think you might need to just go through the docs from start to finish, or start building a proof of concept (e.g. start with 3 machines/environments and 2 configs per machine/environment). I don't know of an open source example (or a contrived example) that is going to convince you that ansible will do this at the scale you're referencing, but it will, and it has a nice abstraction for it. It's what ansible was designed for - orchestration of machines/environments at scale.

Here's a couple links that might point you in the right direction, but I recommend reading through the entire ansible documentation, it's pretty decent. And spending a day doing a proof of concept will help focus your questions from the general "can it do this conceptual thing" to the specific "where do I define my option/variable pairs for configA.conf.j2 template of AppB" and should take you in the right direction.

http://docs.ansible.com/template_module.html
http://docs.ansible.com/faq.html
http://docs.ansible.com/playbooks_roles.html#roles


--
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.

For more options, visit https://groups.google.com/d/optout.



--
The king’s heart is like a stream of water directed by the Lord; He guides it wherever He pleases.

Mark Phillips

unread,
Feb 10, 2015, 12:51:34 PM2/10/15
to ansible...@googlegroups.com
Well worth looking at doing this with inventory and group_vars Chris - ideally you want to avoid embedding lots of {% if %} stuff in templates, because it makes it harder for people to follow what you're doing.

Make the software do the work for you...

Chris Short

unread,
Feb 10, 2015, 4:19:08 PM2/10/15
to ansible...@googlegroups.com
I found this today: http://www.geedew.com/setting-up-ansible-for-multiple-environment-deployments/

With the help provided here and this article I believe I completely grasp the concept of group_vars/host_vars. 

Thanks for the help, everyone.
Reply all
Reply to author
Forward
0 new messages