# Ansible support for Consul.

**URL:** <https://forum.ansible.com/t/ansible-support-for-consul/17161>\
**Category:** Ansible Developer\
**Created:** [December 30, 2014, 4:12pm UTC](https://forum.ansible.com/t/ansible-support-for-consul/17161 "2014-12-30T16:12:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Gargan](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Stephen\_Gargan](https://forum.ansible.com/u/Stephen_Gargan)\
**Post date:** [December 30, 2014, 4:12pm UTC](https://forum.ansible.com/t/ansible-support-for-consul/17161/1 "2014-12-30T16:12:41Z")

</div>

I’ve been working on support for interacting with Consul from within Ansible. Currently there is support for manipulating services, checks, acls and values in the kv store. There is also an inventory that gets built from the contents of the catalog, grouping nodes by service and availability. Its pretty close to ready for submission and I have a few questions before creating the pull request.

The modules have been added in the extras repo, but there are other files, the lookup module, inventory script and importantly the integration tests that don’t really fit there and need to be added to the project proper to work. What is the suggested way to add module submissions with tests and other project level files? Can the inventory and lookups go in the extras project? What about the tests? What should I be thinking about for v2 support?

One of the modules is named consul and this happens to have the same name as the inventory script consul.py, this can cause collisions in ‘hacking’ mode where the runtime loads the inventory script instead of the module. Where would I look to exclude the inventory plugins from the module lookup? I could rename the consul module as a workaround, but would prefer to exclude the inventory scripts if possible.

Also, the tests need a working Consul cluster to pass, I’ve put together a Vagrant project and associated roles to spin up a new cluster and add an agent to the local host. If the local agent can’t be found the tests will not run. The roles and vagrant project can be found here

[https://github.com/sgargan/consul-vagrant](https://github.com/sgargan/consul-vagrant)

Vagrant has been really useful for testing, it might be something worth formalizing into the test infrastructure so that the destructive tests can be easily and cleanly run. If the tests for a module were easy to run in isolation, PRs could be automatically verified, I think this TDD/CI approach would definitely help to speed up the throughput of submissions. What are your thoughts on this? I’d be happy to help out with such an effort.

regards,

Steve

---

<div class="post-metadata">

**Author:** ![Hagai\_Kariti](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hagai\_Kariti](https://forum.ansible.com/u/Hagai_Kariti)\
**Post date:** [December 30, 2014, 5:00pm UTC](https://forum.ansible.com/t/ansible-support-for-consul/17161/2 "2014-12-30T17:00:42Z")

</div>

Hi Steve,

We’re also using Ansible and starting to use Consul and we’d love to contribute. Can you share a link to your code?

Thanks

---

<div class="post-metadata">

**Author:** ![Stephen\_Gargan](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Stephen\_Gargan](https://forum.ansible.com/u/Stephen_Gargan)\
**Post date:** [December 30, 2014, 5:48pm UTC](https://forum.ansible.com/t/ansible-support-for-consul/17161/3 "2014-12-30T17:48:22Z")

</div>

I’ve not pushed it yet, should do pretty soon though once I have these issues cleared up. I’ll let you know when its available. In the meantime if you’re looking to get started you could checkout the consul role from galaxy. It’s fairly fully featured and I’ve used it extensively myself but it would be nice to get a second opinion.

thanks,

Steve.

---

<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:** [January 2, 2015, 3:57pm UTC](https://forum.ansible.com/t/ansible-support-for-consul/17161/4 "2015-01-02T15:57:39Z")

</div>

Stephen,

Create separate PRs for each module, tests, inventory script and  
lookup plugin, inventory testse, and lookup go against the main repo  
github.com/ansibile/ansible. Leave the modules in the extras repo.

Since the inventory and modules go in different paths the name  
collision is not important (in your setup inventory is somehow  
included in module path, which should never happen).

---

<div class="post-metadata">

**Author:** ![Stephen\_Gargan](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Stephen\_Gargan](https://forum.ansible.com/u/Stephen_Gargan)\
**Post date:** [January 24, 2015, 2:25am UTC](https://forum.ansible.com/t/ansible-support-for-consul/17161/5 "2015-01-24T02:25:28Z")

</div>

Finally got round to making the submissions, you can find them here

[https://github.com/ansible/ansible/pull/10078](https://github.com/ansible/ansible/pull/10078)  
[https://github.com/ansible/ansible-modules-extras/pull/225](https://github.com/ansible/ansible-modules-extras/pull/225)

The modules are reasonably complete for the consul 0.4, and I will update once 0.5 is released.

Consul is really great kit and is very complimentary to Ansible, together they are extremely useful. I hope others will find these additions as helpful as I have.

regards,

Steve.
