AnsibleShipyard / ansible-zookeeper

Ansible playbook for ZooKeeper
MIT License
95 stars 114 forks source link

Customize own hostname with a new variable #82

Closed jordiclariana closed 6 years ago

jordiclariana commented 6 years ago

There are sometimes when inventory_hostname is not the real hostname of your machine, and you want to specify which fact from ansible represents better your hostname.

For this I added zookeeper_own_hostname which by default equals to inventory_hostname but let you for instance overwrite it by ansible_nodename or whatever other variable or value you need.

This change is backwards compatible.

ernestas-poskus commented 6 years ago

Hey, thank you for contribution :+1: everything looks good to me expect new variable own part, it lacks intention. How about zookeeper_hosts_hostname ?

Have you thought about multiple array declarations?

      zookeeper_hosts:
        - host: "{{zookeeper_own_hostname}}" # the machine running
          id: 1
        - host: "{{zookeeper_own_hostname}}" # the machine running
          id: 2

For example I am setting hosts with this block:

zookeeper_hosts: "
    {%- set ips = [] %}
    {%- for host in groups['zookeepers'] %}
    {{- ips.append(dict(id=loop.index, host=host, ip=hostvars[host]['ansible_' + lo_host_ipv4_interface].ipv4.address)) }}
    {%- endfor %}
    {{- ips -}}"
jordiclariana commented 6 years ago

No problem on the variable name change, it honestly makes sense.

About the case you mention, I think it will work with the default zookeeper_hosts_hostname: inventory_hostname, because inventory_hostname is the one returned by groups['zookeepers'].

I tested locally and it is like this.

ernestas-poskus commented 6 years ago

Neat! thank you for contribution :+1: