From 84c13577b16ce3e47664928e09adca17dab3daf8 Mon Sep 17 00:00:00 2001 From: Jordi Clariana Date: Thu, 5 Apr 2018 15:46:54 +0200 Subject: [PATCH] Customize own hostname with a new variable --- README.md | 3 ++- defaults/main.yml | 3 ++- templates/myid.j2 | 4 ++-- tests/test.yml | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f8c5d18..3ef0dda 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,10 @@ zookeeper_dir: /opt/zookeeper-{{zookeeper_version}} # or /usr/share/zookeeper wh zookeeper_conf_dir: {{zookeeper_dir}} # or /etc/zookeeper when zookeeper_debian_apt_install is true zookeeper_tarball_dir: /opt/src +zookeeper_hosts_hostname: "{{inventory_hostname}}" # List of dict (i.e. {zookeeper_hosts:[{host:,id:},{host:,id:},...]}) zookeeper_hosts: - - host: "{{inventory_hostname}}" # the machine running + - host: "{{zookeeper_hosts_hostname}}" # the machine running id: 1 # Dict of ENV settings to be written into the (optional) conf/zookeeper-env.sh diff --git a/defaults/main.yml b/defaults/main.yml index 7b6400c..3313abb 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -31,9 +31,10 @@ zookeeper_tarball_dir: /opt/src zookeeper_rolling_log_file_max_size: 10MB zookeeper_max_rolling_log_file_count: 10 +zookeeper_hosts_hostname: "{{inventory_hostname}}" # List of dict (i.e. {zookeeper_hosts:[{host:,id:},{host:,id:},...]}) zookeeper_hosts: - - host: "{{inventory_hostname}}" # the machine running + - host: "{{zookeeper_hosts_hostname}}" # the machine running id: 1 # Dict of ENV settings to be written into the (optional) conf/zookeeper-env.sh diff --git a/templates/myid.j2 b/templates/myid.j2 index a0122d9..9de7bc1 100644 --- a/templates/myid.j2 +++ b/templates/myid.j2 @@ -1,10 +1,10 @@ {% for server in zookeeper_hosts %} {% if server.host is defined %} -{% if server.host == inventory_hostname %} +{% if server.host == zookeeper_hosts_hostname %} {{ server.id }} {% endif %} {% else %} -{% if server == inventory_hostname %} +{% if server == zookeeper_hosts_hostname %} {{ loop.index }} {% endif %} {% endif %} diff --git a/tests/test.yml b/tests/test.yml index cf59ee2..fec48c8 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -23,7 +23,7 @@ roles: - role: role_under_test zookeeper_hosts: - - host: "{{inventory_hostname}}" # the machine running + - host: "{{zookeeper_hosts_hostname}}" # the machine running id: 2 - hosts: localhost @@ -45,7 +45,7 @@ roles: - role: role_under_test zookeeper_hosts: - - "{{inventory_hostname}}" + - "{{zookeeper_hosts_hostname}}" - hosts: localhost connection: local @@ -68,7 +68,7 @@ zookeeper_version: 3.4.11 zookeeper_dir: /opt/zookeeper-{{zookeeper_version}} zookeeper_hosts: - - host: "{{inventory_hostname}}" # the machine running + - host: "{{zookeeper_hosts_hostname}}" # the machine running ip: '192.168.0.1' id: 2