From d451d277239a75c71841a6ff233763c34e5b360b Mon Sep 17 00:00:00 2001 From: Michael Russell Date: Mon, 18 Jun 2018 07:37:51 +0200 Subject: [PATCH] Only symlink systemd file for systemd systems --- tasks/elasticsearch-config.yml | 47 ++++++++++--------- .../helpers/serverspec/config_spec.rb | 4 -- .../helpers/serverspec/multi_spec.rb | 17 ------- .../helpers/serverspec/package_spec.rb | 4 -- .../helpers/serverspec/xpack_spec.rb | 4 -- .../helpers/serverspec/xpack_standard_spec.rb | 4 -- 6 files changed, 24 insertions(+), 56 deletions(-) diff --git a/tasks/elasticsearch-config.yml b/tasks/elasticsearch-config.yml index 57e6826..d7bb095 100644 --- a/tasks/elasticsearch-config.yml +++ b/tasks/elasticsearch-config.yml @@ -86,29 +86,30 @@ content: '' when: ansible_os_family == 'RedHat' -- name: Check if default systemd file exists - stat: - path: "{{ sysd_script }}" - register: sysd_stat_result - -- name: Remove if it is a normal file - file: - path: "{{ sysd_script }}" - state: absent - when: not sysd_stat_result.stat.islnk - -- name: Create a symbolic link to the default systemd location to the first instance running on this host - become: yes - file: - state: link - src: "{{ instance_sysd_script }}" - path: "{{ sysd_script }}" - when: - - use_system_d - - not sysd_stat_result.stat.islnk - notify: - - reload systemd configuration - - restart elasticsearch +- name: Symlink default systemd service to first instance of elasticsearch + when: use_system_d + block: + - name: Check if default systemd file exists + stat: + path: "{{ sysd_script }}" + register: sysd_stat_result + + - name: Remove if it is a normal file + file: + path: "{{ sysd_script }}" + state: absent + when: not sysd_stat_result.stat.islnk + + - name: Create a symbolic link to the default systemd location to the first instance running on this host + become: yes + file: + state: link + src: "{{ instance_sysd_script }}" + path: "{{ sysd_script }}" + when: not sysd_stat_result.stat.islnk + notify: + - reload systemd configuration + - restart elasticsearch - name: Delete Default Configuration File become: yes diff --git a/test/integration/helpers/serverspec/config_spec.rb b/test/integration/helpers/serverspec/config_spec.rb index 933dc5f..d84a280 100644 --- a/test/integration/helpers/serverspec/config_spec.rb +++ b/test/integration/helpers/serverspec/config_spec.rb @@ -125,10 +125,6 @@ shared_examples 'config::init' do |vars| end end - describe file('/usr/lib/systemd/system/elasticsearch.service') do - it { should_not exist } - end - describe file('/etc/elasticsearch/elasticsearch.yml') do it { should_not exist } end diff --git a/test/integration/helpers/serverspec/multi_spec.rb b/test/integration/helpers/serverspec/multi_spec.rb index b3ec77a..da6daf0 100644 --- a/test/integration/helpers/serverspec/multi_spec.rb +++ b/test/integration/helpers/serverspec/multi_spec.rb @@ -212,10 +212,6 @@ shared_examples 'multi::init' do |vars| end end - describe file('/usr/lib/systemd/system/elasticsearch.service') do - it { should_not exist } - end - describe file('/etc/elasticsearch/elasticsearch.yml') do it { should_not exist } end @@ -223,18 +219,5 @@ shared_examples 'multi::init' do |vars| describe file('/etc/elasticsearch/logging.yml') do it { should_not exist } end - - - #Test server spec file has been created and modified - currently not possible as not copied for debian 8 - #describe file('/usr/lib/systemd/system/master_elasticsearch.service') do - # it { should be_file } - # it { should contain 'LimitMEMLOCK=infinity' } - #end - - #describe file('/usr/lib/systemd/system/node1_elasticsearch.service') do - # it { should be_file } - # it { should_not contain 'LimitMEMLOCK=infinity' } - #end - end diff --git a/test/integration/helpers/serverspec/package_spec.rb b/test/integration/helpers/serverspec/package_spec.rb index ab37b0d..788cd93 100644 --- a/test/integration/helpers/serverspec/package_spec.rb +++ b/test/integration/helpers/serverspec/package_spec.rb @@ -100,10 +100,6 @@ shared_examples 'package::init' do |vars| end end - describe file('/usr/lib/systemd/system/elasticsearch.service') do - it { should_not exist } - end - describe file('/etc/elasticsearch/elasticsearch.yml') do it { should_not exist } end diff --git a/test/integration/helpers/serverspec/xpack_spec.rb b/test/integration/helpers/serverspec/xpack_spec.rb index aacf949..d3548ac 100644 --- a/test/integration/helpers/serverspec/xpack_spec.rb +++ b/test/integration/helpers/serverspec/xpack_spec.rb @@ -68,10 +68,6 @@ shared_examples 'xpack::init' do |vars| end end - describe file('/usr/lib/systemd/system/elasticsearch.service') do - it { should_not exist } - end - describe file('/etc/elasticsearch/elasticsearch.yml') do it { should_not exist } end diff --git a/test/integration/helpers/serverspec/xpack_standard_spec.rb b/test/integration/helpers/serverspec/xpack_standard_spec.rb index c6d046a..9c35ae5 100644 --- a/test/integration/helpers/serverspec/xpack_standard_spec.rb +++ b/test/integration/helpers/serverspec/xpack_standard_spec.rb @@ -69,10 +69,6 @@ shared_examples 'xpack_standard::init' do |vars| end end - describe file('/usr/lib/systemd/system/elasticsearch.service') do - it { should_not exist } - end - describe file('/etc/elasticsearch/elasticsearch.yml') do it { should_not exist } end