On Thu, 2 Mar 2017, at 10:19, ishan jain wrote:
> I am preparing some Ansible scripts for a service that works in a
> master/slave setup. There is a single docker image for both but the
> master/slave behavior will be acquired after configuring some environment
> variables.
>
> When i explicitly setup each container, this is roughly how my playbook
> would look:
I've dealt with this in 2 different ways in the past depending on scale.
In both cases I have a single group (call it lb for loadbalancer) with
the nodes in it, but use dynamic lookups for the latter more complex
scenario.
In one case, I used per-host variables - effectively a manual
declaration:
/p/i/ansible ╍{} cat host_vars/b*
---
config:
cluster:
primary: "{{ inventory_hostname }}"
backup: b1.local
---
config:
cluster:
primary: "{{ inventory_hostname }}"
backup: b2.local
---
And then these can be reference in the usual way.
The other approach, a little more sophisticated and ideal for larger
setups, I can describe but don't have the code handy.
- all hosts (in your case just 2) are listed in DNS or some other
service discovery tool.
- you retrieve via lookup[1] which returns a list
- you filter the list to remove this node's IP address or hostname
- iterate over the remaining list items to populate your config, in my
case multiple load balance entries
A+
Dave
[1]:
http://docs.ansible.com/ansible/playbooks_lookups.html#the-dns-lookup-dig
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/1488483325.163159.898480904.71770E06%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.