Is this possible with Ansible?

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.

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 %}

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') }}

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

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

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…

http://docs.ansible.com/intro_inventory.html#group-variables

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.