From d34d5e6103ab77d46c6072254df457a0f8ced7b5 Mon Sep 17 00:00:00 2001 From: Dale McDiarmid Date: Tue, 24 Nov 2015 17:32:36 +0000 Subject: [PATCH] Changes to support Hash Map for Config --- .kitchen.yml | 7 ++++- README.md | 2 +- ansible.cfg | 2 +- defaults/main.yml | 9 ++++-- tasks/checkParameters.yml | 6 ++-- tasks/elasticsearch-config.yml | 20 ++++++------- tasks/elasticsearch-plugins.yml | 2 +- tasks/elasticsearch.yml | 7 +++-- templates/elasticsearch.yml.j2 | 51 ++++++++++++++++----------------- test/integration/config.yml | 4 +-- test/integration/multi.yml | 4 +-- test/integration/package.yml | 2 +- test/integration/standard.yml | 4 +-- vars/Debian.yml | 7 +---- vars/main.yml | 2 +- 15 files changed, 65 insertions(+), 64 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index 1122b95..68bdc44 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -18,6 +18,7 @@ platforms: - apt-get update && apt-get install -y software-properties-common && add-apt-repository -y ppa:ansible/ansible - apt-get update && apt-get -y -q install ansible python-apt python-pycurl use_sudo: false + #run_command: "-e ENV ANSIBLE_HASH_BEHAVIOUR=merge" - name: debian-7 driver_config: image: electrical/debian:7.3 @@ -26,12 +27,16 @@ platforms: - echo 'deb http://http.debian.net/debian/ wheezy-backports main' >> /etc/apt/sources.list - apt-get update - apt-get install -y -q ansible + - apt-get install -y -q net-tools use_sudo: false - name: debian-8 driver_config: image: electrical/debian:8 privileged: true - provision_command: apt-get -y -q install ansible + provision_command: + - apt-get update + - apt-get install -y -q ansible + - apt-get install -y -q net-tools use_sudo: false - name: centos-6 driver_config: diff --git a/README.md b/README.md index f8b5517..77801fd 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ hosts: my_host - .... your tasks ... ``` -By default es_multicast_enabled is false. If this is not to true, the user is required to specify the following additional parameters: +By default es_multicast_enabled is false and the user is required to specify the following additional parameters: 1. es_http_port - the http port for the node 2. es_transport_tcp_port - the transport port for the node diff --git a/ansible.cfg b/ansible.cfg index 613d83b..d7649f6 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,2 +1,2 @@ [defaults] -roles_path = ../ +hash_behaviour = merge \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml index ff4abc0..745fa7b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,6 +9,9 @@ es_scripts: false es_templates: false es_user: elasticsearch es_group: elasticsearch -es_cluster_name: elasticsearch -es_multicast_enabled: false -es_node_name_prefix: "" \ No newline at end of file + +es_config: { + "cluster_name": elasticsearch, + "multicast_enabled": false, + "node_name_prefix": "" +} \ No newline at end of file diff --git a/tasks/checkParameters.yml b/tasks/checkParameters.yml index 242c6a6..892ce03 100644 --- a/tasks/checkParameters.yml +++ b/tasks/checkParameters.yml @@ -1,10 +1,10 @@ # Check for mandatory parameters - fail: msg="Parameter 'es_http_port' must be defined when multicast is disabled" - when: es_multicast_enabled == false and es_http_port is not defined + when: es_config['multicast_enabled'] == false and es_config['http_port'] is not defined - fail: msg="Parameter 'es_transport_tcp_port' must be defined when multicast is disabled" - when: es_multicast_enabled == false and es_transport_tcp_port is not defined + when: es_config['multicast_enabled'] == false and es_config['transport_tcp_port'] is not defined - fail: msg="Parameter 'es_unicast_hosts' must be defined when multicast is disabled" - when: es_multicast_enabled == false and es_unicast_hosts is not defined \ No newline at end of file + when: es_config['multicast_enabled'] == false and es_config['unicast_hosts'] is not defined \ No newline at end of file diff --git a/tasks/elasticsearch-config.yml b/tasks/elasticsearch-config.yml index 98f7a68..c5fad45 100644 --- a/tasks/elasticsearch-config.yml +++ b/tasks/elasticsearch-config.yml @@ -44,15 +44,15 @@ when: es_max_open_files is defined register: elasticsearch_configure -#For directories we also use the {{ es_node_name_prefix }}{{inventory_hostname}} - this helps if we have a shared SAN. {{es_node_name_prefix}}{{default_file | basename} could potentially be used - +#For directories we also use the {{ es_config['node_name_prefix'] }}{{inventory_hostname}} - this helps if we have a shared SAN. {{es_config['node_name_prefix']}}{{default_file | basename} could potentially be used - #init script effectively means this is the default. #Create PID directory - name: Create PID Directory - file: path={{pid_dir}}/{{ es_node_name_prefix }}{{inventory_hostname}} state=directory owner={{ es_user }} group={{ es_group }} + file: path={{pid_dir}}/{{ es_config['node_name_prefix'] }}{{inventory_hostname}} state=directory owner={{ es_user }} group={{ es_group }} - name: Configure PID directory - lineinfile: dest={{instance_default_file}} regexp="^PID_DIR" insertafter="^#PID_DIR" line="PID_DIR={{pid_dir}}/{{ es_node_name_prefix }}{{inventory_hostname}}" + lineinfile: dest={{instance_default_file}} regexp="^PID_DIR" insertafter="^#PID_DIR" line="PID_DIR={{pid_dir}}/{{ es_config['node_name_prefix'] }}{{inventory_hostname}}" register: elasticsearch_configure - set_fact: es_data_dir={{default_data_dir}} @@ -60,30 +60,30 @@ #include the host name as potentially shared SAN - name: Create data dir - file: state=directory path={{ es_data_dir }}/{{ es_node_name_prefix }}{{inventory_hostname}} owner={{ es_user }} group={{ es_group }} + file: state=directory path={{ es_data_dir }}/{{ es_config['node_name_prefix'] }}{{inventory_hostname}} owner={{ es_user }} group={{ es_group }} - name: Configure data store - lineinfile: dest={{instance_default_file}} regexp="^DATA_DIR" insertafter="^#DATA_DIR" line="DATA_DIR={{ es_data_dir }}/{{ es_node_name_prefix }}{{inventory_hostname}}" + lineinfile: dest={{instance_default_file}} regexp="^DATA_DIR" insertafter="^#DATA_DIR" line="DATA_DIR={{ es_data_dir }}/{{ es_config['node_name_prefix'] }}{{inventory_hostname}}" register: elasticsearch_configure - set_fact: es_work_dir={{default_work_dir}} when: es_work_dir is undefined - name: Create work dir - file: state=directory path={{ es_work_dir }}/{{ es_node_name_prefix }}{{inventory_hostname}} owner={{ es_user }} group={{ es_group }} + file: state=directory path={{ es_work_dir }}/{{ es_config['node_name_prefix'] }}{{inventory_hostname}} owner={{ es_user }} group={{ es_group }} - name: Configure work directory - lineinfile: dest={{instance_default_file}} regexp="^WORK_DIR" insertafter="^#WORK_DIR" line="WORK_DIR={{ es_work_dir }}/{{ es_node_name_prefix }}{{inventory_hostname}}" + lineinfile: dest={{instance_default_file}} regexp="^WORK_DIR" insertafter="^#WORK_DIR" line="WORK_DIR={{ es_work_dir }}/{{ es_config['node_name_prefix'] }}{{inventory_hostname}}" register: elasticsearch_configure - set_fact: es_log_dir={{default_log_dir}} when: es_log_dir is undefined - name: Create log dir - file: state=directory path={{ es_log_dir }}/{{ es_node_name_prefix }}{{inventory_hostname}} owner={{ es_user }} group={{ es_group }} + file: state=directory path={{ es_log_dir }}/{{ es_config['node_name_prefix'] }}{{inventory_hostname}} owner={{ es_user }} group={{ es_group }} - name: Configure log directory - lineinfile: dest={{instance_default_file}} regexp="^LOG_DIR" insertafter="^#LOG_DIR" line="LOG_DIR={{ es_log_dir }}/{{ es_node_name_prefix }}{{inventory_hostname}}" + lineinfile: dest={{instance_default_file}} regexp="^LOG_DIR" insertafter="^#LOG_DIR" line="LOG_DIR={{ es_log_dir }}/{{ es_config['node_name_prefix'] }}{{inventory_hostname}}" register: elasticsearch_configure #required so that the ES_HOME does not change between instances @@ -104,7 +104,7 @@ #Apply changes to init script - NAME can be changed in Debian start script - name: Name Node in Init Script - lineinfile: dest={{instance_init_script}} regexp="^NAME" line="NAME={{es_node_name_prefix}}{{default_file | basename}}" + lineinfile: dest={{instance_init_script}} regexp="^NAME" line="NAME={{es_config['node_name_prefix']}}{{default_file | basename}}" register: elasticsearch_configure when: ansible_os_family == 'Debian' diff --git a/tasks/elasticsearch-plugins.yml b/tasks/elasticsearch-plugins.yml index 6da7dea..15bdf91 100644 --- a/tasks/elasticsearch-plugins.yml +++ b/tasks/elasticsearch-plugins.yml @@ -12,4 +12,4 @@ failed_when: "'Failed to install' in command_result.stderr" changed_when: command_result.rc == 0 with_items: es_plugins - when: ( ansible_os_family == 'RedHat' or ansible_os_family == 'Debian' ) + when: ( ansible_os_family == 'RedHat' or ansible_os_family == 'Debian' ) \ No newline at end of file diff --git a/tasks/elasticsearch.yml b/tasks/elasticsearch.yml index aca22c7..ca67ccd 100644 --- a/tasks/elasticsearch.yml +++ b/tasks/elasticsearch.yml @@ -1,7 +1,8 @@ --- -- set_fact: instance_default_file={{default_file | dirname}}/{{es_node_name_prefix}}{{default_file | basename}} -- set_fact: instance_init_script={{init_script | dirname }}/{{es_node_name_prefix}}{{init_script | basename}} -- set_fact: instance_config_directory={{ es_conf_dir }}/{{es_node_name_prefix}}elasticsearch +- debug: msg="Node configuration {{ es_config }} " +- set_fact: instance_default_file={{default_file | dirname}}/{{es_config["node_name_prefix"]}}{{default_file | basename}} +- set_fact: instance_init_script={{init_script | dirname }}/{{es_config['node_name_prefix']}}{{init_script | basename}} +- set_fact: instance_config_directory={{ es_conf_dir }}/{{es_config['node_name_prefix']}}elasticsearch diff --git a/templates/elasticsearch.yml.j2 b/templates/elasticsearch.yml.j2 index 16237f6..8633a78 100644 --- a/templates/elasticsearch.yml.j2 +++ b/templates/elasticsearch.yml.j2 @@ -29,29 +29,29 @@ # Cluster name identifies your cluster for auto-discovery. If you're running # multiple clusters on the same network, make sure you're using unique names. # -cluster.name: {{ es_cluster_name }} +cluster.name: {{ es_config['cluster_name'] }} #################################### Node ##################################### # Node names are generated dynamically on startup, so you're relieved # from configuring them manually. You can tie this node to a specific name: # -node.name: {{es_node_name_prefix}}{{inventory_hostname}} +node.name: {{ es_config['node_name_prefix'] }}{{inventory_hostname}} # Every node can be configured to allow or deny being eligible as the master, # and to allow or deny to store the data. # # Allow this node to be eligible as a master node (enabled by default): # -{% if es_master_node is defined %} -node.master: {{es_master_node | lower}} +{% if es_config['master_node'] is defined %} +node.master: {{ es_config['master_node'] | lower}} {% endif %} # # Allow this node to store data (enabled by default): # -{% if es_data_node is defined %} -node.data: {{es_data_node | lower}} +{% if es_config['data_node'] is defined %} +node.data: {{ es_config['data_node'] | lower}} {% endif %} # Use the Cluster Health API [http://localhost:9200/_cluster/health], the @@ -65,8 +65,8 @@ node.data: {{es_data_node | lower}} # for customized shard allocation filtering, or allocation awareness. An attribute # is a simple key value pair, similar to node.key: value, here is an example: # -{% if es_node_rack is defined %} -node.rack: {{ es_node_rack }} +{% if es_config['node_rack'] is defined %} +node.rack: {{ es_config['node_rack'] }} {% endif %} # By default, multiple nodes are allowed to start from the same installation location @@ -89,13 +89,13 @@ node.rack: {{ es_node_rack }} # Set the number of shards (splits) of an index (5 by default) if provided: -{% if es_index_number_of_shards is defined %} -index.number_of_shards: {{ es_index_number_of_shards }} +{% if es_config['index_number_of_shards'] is defined %} +index.number_of_shards: {{ es_config['index_number_of_shards'] }} {% endif %} # Set the number of replicas (additional copies) of an index (1 by default) if provided: -{% if es_index_number_of_replicas is defined %} -index.number_of_replicas: {{ es_index_number_of_replicas }} +{% if es_config['index_number_of_replicas'] is defined %} +index.number_of_replicas: {{ es_config['index_number_of_replicas'] }} {% endif %} @@ -124,10 +124,7 @@ index.number_of_replicas: {{ es_index_number_of_replicas }} #################################### Paths #################################### # Path to directory containing configuration (this file and logging.yml): -# -{% if es_conf_dir is defined %} -path.conf: {{ es_conf_dir }} -{% endif %} +path.conf: {{ instance_config_directory }} # Path to directory where to store index data allocated for this node. @@ -169,8 +166,8 @@ path.logs: {{ es_log_dir }} # # Set this property to true to lock the memory: # -{% if es_m_lock_enabled is defined %} -bootstrap.mlockall: {{es_m_lock_enabled | lower}} +{% if es_config['m_lock_enabled'] is defined %} +bootstrap.mlockall: {{ es_config['m_lock_enabled'] | lower}} {% endif %} @@ -200,15 +197,15 @@ bootstrap.mlockall: {{es_m_lock_enabled | lower}} # Set both 'bind_host' and 'publish_host': # -{% if es_network_host is defined %} -network.host: {{ es_network_host }} +{% if es_config['network_host'] is defined %} +network.host: {{ es_config['network_host'] }} {% endif %} # Set a custom port for the node to node communication (9300 by default): # -{% if es_transport_tcp_port is defined %} -transport.tcp.port: {{ es_transport_tcp_port }} +{% if es_config['transport_tcp_port'] is defined %} +transport.tcp.port: {{ es_config['transport_tcp_port'] }} {% endif %} # Enable compression for all communication between nodes (disabled by default): @@ -217,8 +214,8 @@ transport.tcp.port: {{ es_transport_tcp_port }} # Set a custom port to listen for HTTP traffic (9200 by default): # -{% if es_http_port is defined %} -http.port: {{ es_http_port }} +{% if es_config['http_port'] is defined %} +http.port: {{ es_config['http_port'] }} {% endif %} # Set a custom allowed content length: @@ -316,7 +313,7 @@ http.port: {{ es_http_port }} # # 1. Disable multicast discovery (enabled by default): # -discovery.zen.ping.multicast.enabled: {{es_multicast_enabled | lower }} +discovery.zen.ping.multicast.enabled: {{ es_config['multicast_enabled'] | lower }} # # 2. Configure an initial list of master nodes in the cluster @@ -325,8 +322,8 @@ discovery.zen.ping.multicast.enabled: {{es_multicast_enabled | lower }} #We put all the current eligible masters in here. If not specified, we assumes its a master -{% if es_multicast_enabled is defined and not es_multicast_enabled %} -discovery.zen.ping.unicast.hosts: {{es_unicast_hosts}} +{% if es_config['multicast_enabled'] is defined and not es_config['multicast_enabled'] %} +discovery.zen.ping.unicast.hosts: {{ es_config['unicast_hosts'] }} {% endif %} diff --git a/test/integration/config.yml b/test/integration/config.yml index da421b5..c5f8b4c 100644 --- a/test/integration/config.yml +++ b/test/integration/config.yml @@ -4,9 +4,9 @@ hosts: localhost roles: #expand to all available parameters - - { role: elasticsearch, es_unicast_hosts: "localhost:9301", es_http_port: "9201", es_transport_tcp_port: "9301", es_data_node: false, es_master_node: true, es_m_lock_enabled: true, es_multicast_enabled: false, es_node_name_prefix: "node1_", es_cluster_name: "custom-cluster" } + - { role: elasticsearch, es_config: { node_name_prefix: "node1_", cluster_name: "custom-cluster", unicast_hosts: "localhost:9301", http_port: "9201", transport_tcp_port: "9301", data_node: false, master_node: true, m_lock_enabled: true, multicast_enabled: false } } vars: es_scripts: false es_templates: false es_version_lock: false - es_m_lock_enabled: true \ No newline at end of file + es_config: { "m_lock_enabled": true } \ No newline at end of file diff --git a/test/integration/multi.yml b/test/integration/multi.yml index 2a1447c..99d957c 100644 --- a/test/integration/multi.yml +++ b/test/integration/multi.yml @@ -3,6 +3,6 @@ - name: Elasticsearch Config tests hosts: localhost roles: - - { role: elasticsearch, es_node_name_prefix: "node1_", es_unicast_hosts: "localhost:9300", es_http_port: "9201", es_transport_tcp_port: "9301", es_data_node: true, es_master_node: false, es_m_lock_enabled: true, es_multicast_enabled: false } - - { role: elasticsearch, es_node_name_prefix: "master_", es_unicast_hosts: "localhost:9300", es_http_port: "9200", es_transport_tcp_port: "9300", es_data_node: false, es_master_node: true, es_m_lock_enabled: true, es_multicast_enabled: false } + - { role: elasticsearch, es_config: { "multicast_enabled": false, node_name_prefix: "master_", unicast_hosts: "localhost:9300", http_port: "9200", transport_tcp_port: "9300", data_node: false, master_node: true, m_lock_enabled: true,multicast_enabled: false } } + - { role: elasticsearch, es_config: { "multicast_enabled": false, node_name_prefix: "node1_", unicast_hosts: "localhost:9300", http_port: "9201", transport_tcp_port: "9301", data_node: true, master_node: false, m_lock_enabled: true,multicast_enabled: false } } vars: diff --git a/test/integration/package.yml b/test/integration/package.yml index 23fd197..cccc9c8 100644 --- a/test/integration/package.yml +++ b/test/integration/package.yml @@ -2,5 +2,5 @@ - name: Elasticsearch Package tests hosts: localhost roles: - - { role: elasticsearch, es_multicast_enabled: true} + - { role: elasticsearch, es_config: { "multicast_enabled": true } } vars: \ No newline at end of file diff --git a/test/integration/standard.yml b/test/integration/standard.yml index c12deb7..dab13e3 100644 --- a/test/integration/standard.yml +++ b/test/integration/standard.yml @@ -2,9 +2,9 @@ - name: wrapper playbook for kitchen testing "elasticsearch" hosts: localhost roles: - - { role: elasticsearch, es_multicast_enabled: true} + - { role: elasticsearch, es_config: { "multicast_enabled": true } } vars: es_use_repository: "true" es_plugins: - plugin: lmenezes/elasticsearch-kopf - version: master + version: master \ No newline at end of file diff --git a/vars/Debian.yml b/vars/Debian.yml index 5c07034..7ad3450 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -3,9 +3,4 @@ java: "openjdk-7-jre-headless" default_file: "/etc/default/elasticsearch" init_script: "/etc/init.d/elasticsearch" es_conf_dir: "/etc/elasticsearch" -es_home: "/usr/share/elasticsearch" - -default_data_dir: "/var/lib/elasticsearch" -default_log_dir: "/var/log/elasticsearch" -default_work_dir: "/tmp/elasticsearch" -default_pid_dir: "/var/run/elasticsearch" \ No newline at end of file +es_home: "/usr/share/elasticsearch" \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml index d5bd5cf..0cd1e77 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -5,4 +5,4 @@ pid_dir: "/var/run/elasticsearch" #Needed to provide default directories default_data_dir: "/var/lib/elasticsearch" default_log_dir: "/var/log/elasticsearch" -default_work_dir: "/tmp/elasticsearch" +default_work_dir: "/tmp/elasticsearch" \ No newline at end of file