# Is this possible with Ansible?

**URL:** <https://forum.ansible.com/t/is-this-possible-with-ansible/17480>\
**Category:** Ansible Project\
**Created:** [February 9, 2015, 9:19pm UTC](https://forum.ansible.com/t/is-this-possible-with-ansible/17480 "2015-02-09T21:19:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Short](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Short](https://forum.ansible.com/u/Chris_Short)\
**Post date:** [February 9, 2015, 9:19pm UTC](https://forum.ansible.com/t/is-this-possible-with-ansible/17480/1 "2015-02-09T21:19:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brent\_Langston1](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@Brent\_Langston1](https://forum.ansible.com/u/Brent_Langston1)\
**Post date:** [February 9, 2015, 10:05pm UTC](https://forum.ansible.com/t/is-this-possible-with-ansible/17480/2 "2015-02-09T22:05:13Z")

</div>

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](http://foo.example.com);  
{% elif ansible\_local.oscar.tags.environment == “staging” %}  
server\_name [foo-staging.example.com](http://foo-staging.example.com);  
{% else %}  
server\_name {{ ansible\_fqdn }};  
{% endif %}

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 9, 2015, 10:10pm UTC](https://forum.ansible.com/t/is-this-possible-with-ansible/17480/3 "2015-02-09T22:10:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chris\_Short](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Short](https://forum.ansible.com/u/Chris_Short)\
**Post date:** [February 10, 2015, 12:51pm UTC](https://forum.ansible.com/t/is-this-possible-with-ansible/17480/4 "2015-02-10T12:51:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Peter\_Buckley](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@Peter\_Buckley](https://forum.ansible.com/u/Peter_Buckley)\
**Post date:** [February 10, 2015, 3:17pm UTC](https://forum.ansible.com/t/is-this-possible-with-ansible/17480/5 "2015-02-10T15:17:10Z")

</div>

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/template_module.html)  
[http://docs.ansible.com/faq.html](http://docs.ansible.com/faq.html)  
[http://docs.ansible.com/playbooks\_roles.html#roles](http://docs.ansible.com/playbooks_roles.html#roles)

---

<div class="post-metadata">

**Author:** ![Mark\_Phillips](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mark\_Phillips](https://forum.ansible.com/u/Mark_Phillips)\
**Post date:** [February 10, 2015, 5:51pm UTC](https://forum.ansible.com/t/is-this-possible-with-ansible/17480/6 "2015-02-10T17:51:34Z")

</div>

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](http://docs.ansible.com/intro_inventory.html#group-variables)

---

<div class="post-metadata">

**Author:** ![Chris\_Short](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Short](https://forum.ansible.com/u/Chris_Short)\
**Post date:** [February 10, 2015, 9:19pm UTC](https://forum.ansible.com/t/is-this-possible-with-ansible/17480/7 "2015-02-10T21:19:08Z")

</div>

I found this today: [http://www.geedew.com/setting-up-ansible-for-multiple-environment-deployments/](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.
