Compare commits

...

5 commits

17 changed files with 152 additions and 304 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
.kitchen/*
*.pyc

View file

@ -1,27 +0,0 @@
---
driver:
name: docker_cli
transport:
name: docker_cli
provisioner:
name: ansible_playbook
hosts: localhost
require_ansible_repo: false
require_ansible_omnibus: false
require_chef_for_busser: true
ansible_verbose: false
ansible_inventory: ./test/integration/inventory
platforms:
- name: debian-9
driver_config:
image: "nishiki/debian9:ansible-<%= ENV['ANSIBLE_VERSION'] ? ENV['ANSIBLE_VERSION'] : '2.7' %>"
command: /bin/systemd
volume:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
security_opt: seccomp=unconfined
suites:
- name: default

View file

@ -5,6 +5,15 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
## [Unreleased]
### Changed
- replace kitchen to molecule
### Fixed
- no_log only api_password for elasticsearch_template module
- add full python3 support
## v1.1.0 - 2019-11-21
### Added

View file

@ -1,8 +0,0 @@
source 'https://rubygems.org'
group :development do
gem 'kitchen-ansible'
gem 'kitchen-docker_cli'
gem 'rubocop', '0.50.0'
gem 'test-kitchen'
end

View file

@ -1,130 +0,0 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
bcrypt_pbkdf (1.0.1)
builder (3.2.3)
ed25519 (1.2.4)
equatable (0.6.1)
erubis (2.7.0)
ffi (1.11.1)
gssapi (1.3.0)
ffi (>= 1.0.1)
gyoku (1.3.1)
builder (>= 2.1.2)
httpclient (2.8.3)
kitchen-ansible (0.50.1)
net-ssh (>= 3)
test-kitchen (>= 1.4)
kitchen-docker_cli (0.19.0)
test-kitchen (>= 1.3)
license-acceptance (1.0.13)
pastel (~> 0.7)
tomlrb (~> 1.2)
tty-box (~> 0.3)
tty-prompt (~> 0.18)
little-plugger (1.1.4)
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
mixlib-install (3.11.21)
mixlib-shellout
mixlib-versioning
thor
mixlib-shellout (3.0.7)
mixlib-versioning (1.2.7)
multi_json (1.13.1)
necromancer (0.5.0)
net-scp (2.0.0)
net-ssh (>= 2.6.5, < 6.0.0)
net-ssh (5.2.0)
net-ssh-gateway (2.0.0)
net-ssh (>= 4.0.0)
nori (2.6.0)
parallel (1.17.0)
parser (2.6.4.0)
ast (~> 2.4.0)
pastel (0.7.3)
equatable (~> 0.6)
tty-color (~> 0.5)
powerpack (0.1.2)
rainbow (2.2.2)
rake
rake (12.3.3)
rubocop (0.50.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.10.1)
rubyntlm (0.6.2)
rubyzip (1.2.3)
strings (0.1.6)
strings-ansi (~> 0.1)
unicode-display_width (~> 1.5)
unicode_utils (~> 1.4)
strings-ansi (0.1.0)
test-kitchen (2.3.2)
bcrypt_pbkdf (~> 1.0)
ed25519 (~> 1.2)
license-acceptance (~> 1.0, >= 1.0.11)
mixlib-install (~> 3.6)
mixlib-shellout (>= 1.2, < 4.0)
net-scp (>= 1.1, < 3.0)
net-ssh (>= 2.9, < 6.0)
net-ssh-gateway (>= 1.2, < 3.0)
thor (~> 0.19)
winrm (~> 2.0)
winrm-elevated (~> 1.0)
winrm-fs (~> 1.1)
thor (0.20.3)
tomlrb (1.2.8)
tty-box (0.4.1)
pastel (~> 0.7.2)
strings (~> 0.1.6)
tty-cursor (~> 0.7)
tty-color (0.5.0)
tty-cursor (0.7.0)
tty-prompt (0.19.0)
necromancer (~> 0.5.0)
pastel (~> 0.7.0)
tty-reader (~> 0.6.0)
tty-reader (0.6.0)
tty-cursor (~> 0.7)
tty-screen (~> 0.7)
wisper (~> 2.0.0)
tty-screen (0.7.0)
unicode-display_width (1.6.0)
unicode_utils (1.4.0)
winrm (2.3.2)
builder (>= 2.1.2)
erubis (~> 2.7)
gssapi (~> 1.2)
gyoku (~> 1.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (>= 1.6.1, < 3.0)
nori (~> 2.0)
rubyntlm (~> 0.6.0, >= 0.6.1)
winrm-elevated (1.1.1)
winrm (~> 2.0)
winrm-fs (~> 1.0)
winrm-fs (1.3.2)
erubis (~> 2.7)
logging (>= 1.6.1, < 3.0)
rubyzip (~> 1.1)
winrm (~> 2.0)
wisper (2.0.0)
PLATFORMS
ruby
DEPENDENCIES
kitchen-ansible
kitchen-docker_cli
rubocop (= 0.50.0)
test-kitchen
BUNDLED WITH
1.16.6

View file

@ -47,25 +47,12 @@ Install and configure Elasticsearch
## Development
### Test syntax with yamllint
* install `python` and `python-pip`
* install yamllint `pip install yamllint`
* run `yamllint .`
### Test syntax with ansible-lint
* install `python` and `python-pip`
* install yamllint `pip install ansible-lint`
* run `ansible-lint .`
### Tests with docker
### Test with molecule and docker
* install [docker](https://docs.docker.com/engine/installation/)
* install ruby
* install bundler `gem install bundler`
* install dependencies `bundle install`
* run the tests `kitchen test`
* install `python3` and `python3-pip`
* install molecule and dependencies `pip3 install molecule 'molecule[docker]' ansible-lint testinfra yamllint`
* run `molecule test`
## License

View file

@ -77,7 +77,7 @@ def main():
'mappings': { 'type': 'dict', 'default': {} },
'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:9200' },
'api_user': { 'type': 'str', 'default': None },
'api_password': { 'type': 'str', 'default': None },
'api_password': { 'type': 'str', 'default': None, 'no_log': True },
}
module = AnsibleModule(argument_spec=fields)
changed = False

View file

@ -1,6 +1,6 @@
---
- hosts: localhost
connection: local
- name: Converge
hosts: all
vars:
elasticsearch_heap_size: 512m
elasticsearch_index_templates:
@ -13,6 +13,10 @@
mappings:
metrics:
type: short
roles:
- ansible-role-elasticsearch
#
# tasks:
# - name: "Include ansible-role-elasticsearch"
# include_role:
# name: "ansible-role-elasticsearch"

View file

@ -0,0 +1,18 @@
---
driver:
name: docker
platforms:
- name: debian10
image: nishiki/debian10:molecule
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
command: /bin/systemd
capabilities:
- SYS_ADMIN
lint: |
set -e
yamllint .
ansible-lint
verifier:
name: testinfra

View file

@ -0,0 +1,32 @@
import os
import testinfra.utils.ansible_runner
def test_packages(host):
package = host.package('elasticsearch')
assert package.is_installed
def test_config_file(host):
config = host.file('/etc/elasticsearch/elasticsearch.yml')
assert config.user == 'root'
assert config.group == 'elasticsearch'
assert config.mode == 0o640
assert config.contains('path.data: /var/lib/elasticsearch')
def test_service(host):
service = host.service('elasticsearch')
assert service.is_running
assert service.is_enabled
def test_socket(host):
for port in [9200, 9300]:
socket = host.socket('tcp://127.0.0.1:%d' % (port))
assert socket.is_listening
def test_java_memory(host):
process = host.process.get(user='elasticsearch', comm='java')
assert '-Xms512m' in process.args
assert '-Xmx512m' in process.args
def test_elasticsearch_template(host):
result = host.check_output('curl -v http://127.0.0.1:9200/_template/test')
assert '"number_of_replicas":"1"' in result

21
tasks/config.yml Normal file
View file

@ -0,0 +1,21 @@
---
- name: set heap size
lineinfile:
path: /etc/elasticsearch/jvm.options
regexp: '^-{{ item }}'
line: '-{{ item }}{{ elasticsearch_heap_size }}'
loop:
- Xms
- Xmx
notify: restart elasticsearch
tags: elasticsearch
- name: copy config file
copy:
content: '{{ elasticsearch_full_config|to_yaml }}'
dest: /etc/elasticsearch/elasticsearch.yml
owner: root
group: elasticsearch
mode: 0640
notify: restart elasticsearch
tags: elasticsearch

10
tasks/data.yml Normal file
View file

@ -0,0 +1,10 @@
---
- name: copy index templates
elasticsearch_template:
name: '{{ item.key }}'
index_patterns: '{{ item.value.index_patterns }}'
settings: '{{ item.value.settings|default({}) }}'
mappings: '{{ item.value.mappings|default({}) }}'
loop: '{{ elasticsearch_index_templates|dict2items }}'
run_once: true
tags: elasticsearch

View file

@ -1,78 +1,5 @@
---
- name: install dependencies packages
apt:
name: '{{ packages }}'
vars:
packages:
- apt-transport-https
- python-requests
retries: 2
register: result
until: result is succeeded
tags: elasticsearch
- name: add repository key
apt_key:
url: https://artifacts.elastic.co/GPG-KEY-elasticsearch
retries: 2
register: result
until: result is succeeded
tags: elasticsearch
- name: add repository
apt_repository:
repo: deb https://artifacts.elastic.co/packages/7.x/apt stable main
tags: elasticsearch
- name: install package
apt:
name: elasticsearch
retries: 2
register: result
until: result is succeeded
tags: elasticsearch
- name: set heap size
lineinfile:
path: /etc/elasticsearch/jvm.options
regexp: '^-{{ item }}'
line: '-{{ item }}{{ elasticsearch_heap_size }}'
loop:
- Xms
- Xmx
notify: restart elasticsearch
tags: elasticsearch
- name: copy config file
copy:
content: '{{ elasticsearch_full_config|to_yaml }}'
dest: /etc/elasticsearch/elasticsearch.yml
owner: root
group: elasticsearch
mode: 0640
notify: restart elasticsearch
tags: elasticsearch
- name: enable and start service
systemd:
name: elasticsearch
state: started
enabled: true
tags: elasticsearch
- name: wait for api is available
wait_for:
port: 9200
timeout: 10
tags: elasticsearch
- name: copy index templates
elasticsearch_template:
name: '{{ item.key }}'
index_patterns: '{{ item.value.index_patterns }}'
settings: '{{ item.value.settings|default({}) }}'
mappings: '{{ item.value.mappings|default({}) }}'
no_log: true
loop: '{{ elasticsearch_index_templates|dict2items }}'
run_once: true
tags: elasticsearch
- import_tasks: packages.yml
- import_tasks: config.yml
- import_tasks: service.yml
- import_tasks: data.yml

32
tasks/packages.yml Normal file
View file

@ -0,0 +1,32 @@
---
- name: install dependencies packages
package:
name:
- apt-transport-https
- python-requests
- python3-requests
retries: 2
register: result
until: result is succeeded
tags: elasticsearch
- name: add repository key
apt_key:
url: https://artifacts.elastic.co/GPG-KEY-elasticsearch
retries: 2
register: result
until: result is succeeded
tags: elasticsearch
- name: add repository
apt_repository:
repo: deb https://artifacts.elastic.co/packages/7.x/apt stable main
tags: elasticsearch
- name: install package
package:
name: elasticsearch
retries: 2
register: result
until: result is succeeded
tags: elasticsearch

13
tasks/service.yml Normal file
View file

@ -0,0 +1,13 @@
---
- name: enable and start service
systemd:
name: elasticsearch
state: started
enabled: true
tags: elasticsearch
- name: wait for api is available
wait_for:
port: 9200
timeout: 10
tags: elasticsearch

View file

@ -1,40 +0,0 @@
require 'serverspec'
set :backend, :exec
puts
puts '================================'
puts %x(ansible --version)
puts '================================'
sleep 10
describe package('elasticsearch') do
it { should be_installed }
end
describe file('/etc/elasticsearch/elasticsearch.yml') do
it { should be_file }
it { should be_mode 640 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'elasticsearch' }
it { should contain 'path.data: /var/lib/elasticsearch' }
end
describe service('elasticsearch') do
it { should be_enabled }
it { should be_running.under('systemd') }
end
describe port(9200) do
it { should be_listening }
end
describe command('ps faux | grep elasticsearch') do
its(:stdout) { should contain('-Xms512m -Xmx512m') }
end
describe command('curl -v http://127.0.0.1:9200/_template/test') do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain('"number_of_replicas":"1"') }
end

View file

@ -1 +0,0 @@
localhost