automated the selection of a platform - platform restriction

This commit is contained in:
Rshad Zhran 2019-08-23 13:12:00 +02:00
parent 3de387b358
commit f4e4ed4722
15 changed files with 359 additions and 127 deletions

View File

@ -33,4 +33,3 @@ destroy_worker ="molecule destroy -s worker"
destroy_agent ="molecule destroy -s agent" destroy_agent ="molecule destroy -s agent"
destroy_elasticsearch ="molecule destroy -s elasticsearch" destroy_elasticsearch ="molecule destroy -s elasticsearch"
destroy_kibana ="molecule destroy -s kibana" destroy_kibana ="molecule destroy -s kibana"

View File

@ -1,35 +0,0 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
docker-py = "*"
ansible = "==2.7.13"
molecule = "==2.20.2"
[dev-packages]
[requires]
python_version = "2.7"
[scripts]
test ="molecule test --destroy=never --platform _PLATFORM_"
worker ="molecule test -s worker --destroy=never --platform _PLATFORM_"
agent ="molecule test -s wazuh-agent --destroy=never --platform _PLATFORM_"
elasticsearch ="molecule test -s elasticsearch --destroy=never --platform _PLATFORM_"
kibana ="molecule test -s kibana --destroy=never --platform _PLATFORM_"
# Verify ..
verify ="molecule verify"
verify_worker ="molecule verify -s worker"
verify_agent ="molecule verify -s agent"
verify_elasticsearch ="molecule verify -s elasticsearch"
verify_kibana ="molecule verify -s kibana"
# Destroy ..
destroy ="molecule destroy"
destroy_worker ="molecule destroy -s worker"
destroy_agent ="molecule destroy -s agent"
destroy_elasticsearch ="molecule destroy -s elasticsearch"
destroy_kibana ="molecule destroy -s kibana"

View File

@ -6,7 +6,7 @@ driver:
lint: lint:
name: yamllint name: yamllint
enabled: false enabled: false
platforms: bionics:
- name: manager_bionic - name: manager_bionic
image: solita/ubuntu-systemd:bionic image: solita/ubuntu-systemd:bionic
command: /sbin/init command: /sbin/init
@ -14,31 +14,6 @@ platforms:
- nofile:262144:262144 - nofile:262144:262144
privileged: true privileged: true
memory_reservation: 2048m memory_reservation: 2048m
- name: manager_xenial
image: solita/ubuntu-systemd:xenial
privileged: true
memory_reservation: 2048m
command: /sbin/init
ulimits:
- nofile:262144:262144
# - name: trusty
# image: ubuntu:trusty
# privileged: true
# memory_reservation: 2048m
# ulimits:
# - nofile:262144:262144
# - name: centos6
# image: centos:6
# privileged: true
# memory_reservation: 2048m
# ulimits:
# - nofile:262144:262144
- name: manager_centos7
image: milcom/centos7-systemd
memory_reservation: 2048m
privileged: true
ulimits:
- nofile:262144:262144
provisioner: provisioner:
name: ansible name: ansible
config_options: config_options:

View File

@ -0,0 +1,47 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
enabled: false
platforms:
- name: manager_platform_
image: imagename
command: /sbin/init
ulimits:
- nofile:262144:262144
privileged: true
memory_reservation: 2048m
provisioner:
name: ansible
config_options:
defaults:
hash_behaviour: merge
env:
ANSIBLE_ROLES_PATH: ../../roles
lint:
name: ansible-lint
enabled: true
scenario:
name: default
test_sequence:
- lint
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
#- idempotence
- side_effect
- verify
- cleanup
- destroy
verifier:
name: testinfra
lint:
name: flake8
enabled: true

View File

@ -8,40 +8,14 @@ lint:
options: options:
config-data: config-data:
ignore: .virtualenv ignore: .virtualenv
platforms: bionics:
- name: elasticsearch - name: elasticsearch_bionic
image: solita/ubuntu-systemd:bionic image: solita/ubuntu-systemd:bionic
command: /sbin/init command: /sbin/init
ulimits: ulimits:
- nofile:262144:262144 - nofile:262144:262144
privileged: true privileged: true
memory_reservation: 2048m memory_reservation: 2048m
#- name: xenial
# image: solita/ubuntu-systemd:xenial
# privileged: true
# memory_reservation: 2048m
# command: /sbin/init
# ulimits:
# - nofile:262144:262144
#- name: trusty
#image: ubuntu:trusty
#privileged: true
#memory_reservation: 2048m
#ulimits:
#- nofile:262144:262144
#- name: centos6
# image: centos:6
# privileged: true
# memory_reservation: 2048m
# ulimits:
# - nofile:262144:262144
#- name: centos7
# image: milcom/centos7-systemd
# memory_reservation: 2048m
# privileged: true
# ulimits:
# - nofile:262144:262144
provisioner: provisioner:
name: ansible name: ansible
config_options: config_options:

View File

@ -0,0 +1,57 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
options:
config-data:
ignore: .virtualenv
platforms:
- name: elasticsearch_platform_
image: imagename
command: /sbin/init
ulimits:
- nofile:262144:262144
privileged: true
memory_reservation: 2048m
provisioner:
name: ansible
config_options:
defaults:
hash_behaviour: merge
playbooks:
docker:
create: ../default/create.yml
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
env:
ANSIBLE_ROLES_PATH: ../../roles
lint:
name: ansible-lint
enabled: true
inventory:
group_vars:
all:
elasticsearch_jvm_xms: 512
scenario:
name: elasticsearch
test_sequence:
- lint
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
#- idempotence
- side_effect
- verify
- cleanup
- destroy
verifier:
name: testinfra
lint:
name: flake8

View File

@ -3,4 +3,4 @@
hosts: all hosts: all
roles: roles:
- role: elastic-stack/ansible-elasticsearch - role: elastic-stack/ansible-elasticsearch
elasticsearch_network_host: 'elasticsearch_platform' elasticsearch_network_host: 'elasticsearch_bionic'

View File

@ -8,7 +8,7 @@ lint:
options: options:
config-data: config-data:
ignore: .virtualenv ignore: .virtualenv
platforms: bionics:
- name: kibana_bionic - name: kibana_bionic
image: solita/ubuntu-systemd:bionic image: solita/ubuntu-systemd:bionic
command: /sbin/init command: /sbin/init

View File

@ -0,0 +1,64 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
options:
config-data:
ignore: .virtualenv
platforms:
- name: kibana_platform_
image: imagename
command: /sbin/init
ulimits:
- nofile:262144:262144
privileged: true
memory_reservation: 1024m
- name: kibana_xenial
image: solita/ubuntu-systemd:xenial
privileged: true
memory_reservation: 1024m
command: /sbin/init
ulimits:
- nofile:262144:262144
# - name: trusty
# image: ubuntu:trusty
# memory_reservation: 1024m
# ulimits:
# - nofile:262144:262144
# - name: centos6
# image: centos:6
# privileged: true
# memory_reservation: 1024m
# ulimits:
# - nofile:262144:262144
- name: kibana_centos7
image: milcom/centos7-systemd
memory_reservation: 1024m
privileged: true
ulimits:
- nofile:262144:262144
provisioner:
name: ansible
config_options:
defaults:
hash_behaviour: merge
playbooks:
docker:
create: ../default/create.yml
destroy: ../default/destroy.yml
env:
ANSIBLE_ROLES_PATH: ../../roles
lint:
name: ansible-lint
enabled: true
inventory:
group_vars:
all:
elasticsearch_jvm_xms: 256
verifier:
name: testinfra
lint:
name: flake8

View File

@ -3,4 +3,4 @@
hosts: all hosts: all
roles: roles:
- role: elastic-stack/ansible-kibana - role: elastic-stack/ansible-kibana
elasticsearch_network_host: 'elasticsearch_platform' elasticsearch_network_host: 'elasticsearch_bionic'

View File

@ -0,0 +1,89 @@
---
dependency:
name: galaxy
driver:
name: docker
#lint:
# name: yamllint
lint:
name: yamllint
options:
config-data:
ignore: .virtualenv
platforms:
#- name: wazuh_server_centos7
# image: milcom/centos7-systemd
# networks:
# - name: wazuh
# privileged: true
# groups:
# - manager
- name: wazuh_agent_bionic
image: ubuntu:bionic
networks:
- name: wazuh
groups:
- agent
#- name: wazuh_agent_xenial
# image: solita/ubuntu-systemd:xenial
# privileged: true
# command: /sbin/init
# networks:
# - name: wazuh
# groups:
# - agent
#- name: wazuh_agent_trusty
# image: ubuntu:trusty
# networks:
# - name: wazuh
# groups:
# - agent
#- name: wazuh_agent_centos6
# image: centos:6
# networks:
# - name: wazuh
# groups:
# - agent
#- name: wazuh_agent_centos7
# image: milcom/centos7-systemd
# privileged: true
# networks:
# - name: wazuh
# groups:
# - agent
provisioner:
name: ansible
config_options:
defaults:
hash_behaviour: merge
playbooks:
docker:
create: ../default/create.yml
destroy: ../default/destroy.yml
env:
ANSIBLE_ROLES_PATH: ../../roles
inventory:
group_vars:
agent:
api_pass: password
wazuh_managers:
- address: "{{ wazuh_manager_ip }}"
port: 1514
protocol: tcp
api_port: 55000
api_proto: 'http'
api_user: null
wazuh_agent_authd:
enable: true
port: 1515
ssl_agent_ca: null
ssl_agent_cert: null
ssl_agent_key: null
ssl_auto_negotiate: 'no'
lint:
name: ansible-lint
enabled: true
verifier:
name: testinfra
lint:
name: flake8

View File

@ -0,0 +1,18 @@
---
- name: Converge
hosts: all
roles:
- role: wazuh/ansible-wazuh-agent
vars:
wazuh_managers:
- address: 'manager_platform'
port: 1514
protocol: tcp
api_port: 55000
api_proto: 'http'
api_user: ansible
wazuh_agent_authd:
enable: true
port: 1515
ssl_agent_ca: null
ssl_auto_negotiate: 'no'

View File

@ -8,7 +8,7 @@ lint:
options: options:
config-data: config-data:
ignore: .virtualenv ignore: .virtualenv
platforms: bionics:
- name: worker_bionic - name: worker_bionic
image: solita/ubuntu-systemd:bionic image: solita/ubuntu-systemd:bionic
command: /sbin/init command: /sbin/init
@ -16,31 +16,7 @@ platforms:
- nofile:262144:262144 - nofile:262144:262144
privileged: true privileged: true
memory_reservation: 2048m memory_reservation: 2048m
- name: worker_xenial
image: solita/ubuntu-systemd:xenial
privileged: true
memory_reservation: 2048m
command: /sbin/init
ulimits:
- nofile:262144:262144
- name: trusty
#image: ubuntu:trusty
#privileged: true
#memory_reservation: 2048m
#ulimits:
#- nofile:262144:262144
#- name: centos6
# image: centos:6
# privileged: true
# memory_reservation: 2048m
# ulimits:
# - nofile:262144:262144
- name: worker_centos7
image: milcom/centos7-systemd
memory_reservation: 2048m
privileged: true
ulimits:
- nofile:262144:262144
provisioner: provisioner:
name: ansible name: ansible
config_options: config_options:

View File

@ -0,0 +1,54 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
options:
config-data:
ignore: .virtualenv
platforms:
- name: worker_platform_
image: imagename
command: /sbin/init
ulimits:
- nofile:262144:262144
privileged: true
memory_reservation: 2048m
provisioner:
name: ansible
config_options:
defaults:
hash_behaviour: merge
playbooks:
docker:
create: ../default/create.yml
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
env:
ANSIBLE_ROLES_PATH: ../../roles
lint:
name: ansible-lint
enabled: true
scenario:
name: worker
test_sequence:
- lint
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
#- idempotence
- side_effect
- verify
- cleanup
- destroy
verifier:
name: testinfra
lint:
name: flake8

View File

@ -1,24 +1,38 @@
#!/bin/bash #!/bin/bash
paths=( "molecule/default/" "molecule/worker/" "molecule/elasticsearch/" "molecule/kibana/" ) paths=( "molecule/default/" "molecule/worker/" "molecule/elasticsearch/" "molecule/kibana/" )
images=( "solita/ubuntu-systemd:bionic" "solita/ubuntu-systemd:xenial" "milcom/centos7-systemd" "ubuntu:trusty" "centos:6" )
platform=( "bionic" "xenial" "centos7" "trusty" "centos6" )
if [ -z "$1" ] echo "Please select an image. "
select IMAGE in "${images[@]}";
do
echo "You picked $IMAGE ($REPLY)"
break
done
index=$(($REPLY - 1))
if [ -z "$IMAGE" ]
then then
echo "Platform not selected. Please select a platform of [bionuc, xenial or centos7]. => Aborting" echo "Platform not selected. Please select a platform of [bionuc, xenial or centos7]. => Aborting"
echo "Run Instruction: ./run_cluster_mode.sh <platform>" echo "Run Instruction: ./run_cluster_mode.sh <platform>"
exit exit
else else
for i in "${paths[@]}" for i in "${paths[@]}"
do do
cp "$i/playbook.yml.template" "$i/playbook.yml" cp "$i/playbook.yml.template" "$i/playbook.yml"
sed -i "s/platform/$1/g" "$i/playbook.yml" sed -i "s/platform/${platform[$index]}/g" "$i/playbook.yml"
done
cp Pipfile.template Pipfile cp "$i/molecule.yml.template" "$i/molecule.yml"
sed -i "s/_PLATFORM_/$1/g" Pipfile sed -i "s|imagename|${images[$index]}|g" "$i/molecule.yml"
sed -i "s/platform_/${platform[$index]}/g" "$i/molecule.yml"
done
fi fi
sudo pipenv run elasticsearch sudo pipenv run elasticsearch
sudo pipenv run test sudo pipenv run test
sudo pipenv run agent sudo pipenv run worker
sudo pipenv run kibana sudo pipenv run kibana