Created
June 16, 2017 20:32
-
-
Save Kukunin/05ad4852a06c0e828c238f56d515e68a to your computer and use it in GitHub Desktop.
Uniform distribution of servers in ansible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: workers | |
gather_facts: no | |
pre_tasks: | |
- set_fact: sequence_number="{{ ansible_default_ipv4['macaddress'].split(':')[-1] | int('', 16) }}" | |
- set_fact: daemons_count="{{ groups['daemons'] | length }}" | |
- set_fact: daemon_i='{{ (sequence_number|int) % (daemons_count|int)}}' | |
- set_fact: daemon_host="{{ hostvars[groups['daemons'][daemon_i|int]]['ansible_eth0']['ipv4']['address'] }}" | |
- debug: var=daemon_i | |
roles: | |
- role: worker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment