Linking between hosts

Hi all,

First I would like to thank Ansible creators and its great community because this tool really simplifies my day to day life.

I have the following workflow and I want a piece of advice on Step 3:

  • Step 1: create n nodes with a cloud provider (lb, app-1, app-2, index, index-upgrader, db, db-upgrader, log-server, log-store, log-viewer) (done with any cloud module)

  • Step 2: generate an inventory with IP/hostnames gathered from my cloud provider (done with dynamic inventory modules).

  • Step 3: link nodes by alias so that they have knowledge of each other:

  1. log-viewer references log-store
  2. log-server references log-store
  3. index-upgrader references index
  4. db-upgrader references db
  5. app-{1,2} references index, db, log-server
  6. lb references app-{1,2}
  • Step 4: provision and configure nodes with no hardcoded IP adress, only aliases defined in step 3 (regular ansible stuff)
    Solution 1: for each node, generate (with templates and lineinfile directive) the proper hosts file on the nodes manager (the node that runs ansible and the playbook) and copy the hosts file to the node.

That solution would surely work but I was wondering if there were a more elegant way.
Solution 2: use a DNS server. It would also do the trick but it’s rather complex for my needs.
Solution 3: An elegant solution would be to “describe” the linking requirements (like it is done in terraform.io but I don’t want to use another tool, so far ansible covers all my needs) in a file and the module would look-up relevant information in the inventory, generate linking artifacts (host files, or whatever) and apply them to corresponding nodes.

Thank you for your advices.

Regards,

Louis

Hi all,

I decided to go for the 1st solution (/etc/hosts updates) inspired by the following resources:

The desired behavior is the following (idempotent actions) :

  • query the inventory to find candidate hosts (ex: groups[“test.app*”])
  • for each host in candidate_hosts update /etc/host with aliases (ex: update /etc/host so that it contains alias and IP for index, db, log-server)
  • for each host in candidate_hosts generate app configuration files to reference index, db, log-server aliases

I’ll let you know if I get any result.

Regards,

Louis