fixed communications between containers

This commit is contained in:
Rshad Zhran 2019-08-21 15:12:57 +02:00
parent 8bfe42cf86
commit 0e24c57fc6
7 changed files with 68 additions and 32 deletions

13
Pipfile
View File

@ -14,19 +14,12 @@ molecule = "==2.20.2"
python_version = "2.7"
[scripts]
# Normal Case
test ="molecule test"
test ="molecule test --destroy=never"
agent ="molecule test -s wazuh-agent"
elasticsearch ="molecule test -s elasticsearch"
elasticsearch ="molecule test -s elasticsearch --destroy=never"
filebeat ="molecule test -s filebeat"
kibana ="molecule test -s kibana"
# Do Not destroy the created containers afte the test execution ends.
test_still ="molecule test --destroy=never"
agent_still ="molecule test -s wazuh-agent --destroy=never"
elasticsearch_still ="molecule test -s elasticsearch --destroy=never"
filebeat_still ="molecule test -s filebeat --destroy=never"
kibana_still ="molecule test -s kibana --destroy=never"
# Destroy all the existing containers ' Created by Molecule '
destroy_elasticsearch ="molecule destroy -s elasticsearch"
destroy ="molecule destroy"

View File

@ -44,16 +44,15 @@
- name: Create docker network(s)
docker_network:
name: "{{ item }}"
docker_host: "{{ item.docker_host | default('unix://var/run/docker.sock') }}"
name: "new_network"
state: present
with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}"
- name: Create molecule instance(s)
docker_container:
name: "manager"
name: "{{ item.name }}"
docker_host: "{{ item.docker_host | default('unix://var/run/docker.sock') }}"
hostname: "manager"
hostname: "{{ item.name }}"
image: "molecule_local/{{ item.image }}"
state: started
recreate: false
@ -65,7 +64,8 @@
exposed_ports: "{{ item.exposed_ports | default(omit) }}"
published_ports: "{{ item.published_ports | default(omit) }}"
ulimits: "{{ item.ulimits | default(omit) }}"
networks: "{{ item.networks | default(omit) }}"
networks:
- name: "new_network"
dns_servers: "{{ item.dns_servers | default(omit) }}"
register: server
with_items: "{{ molecule_yml.platforms }}"

View File

@ -7,7 +7,7 @@ lint:
name: yamllint
enabled: false
platforms:
- name: bionic
- name: manager
image: solita/ubuntu-systemd:bionic
command: /sbin/init
ulimits:

View File

@ -3,4 +3,5 @@
hosts: all
roles:
- role: wazuh/ansible-wazuh-manager
- { role: wazuh/ansible-filebeat, filebeat_output_elasticsearch_hosts: 'elasticsearch:9200' }

View File

@ -9,13 +9,14 @@ lint:
config-data:
ignore: .virtualenv
platforms:
#- name: bionic
# image: solita/ubuntu-systemd:bionic
# command: /sbin/init
# ulimits:
# - nofile:262144:262144
# privileged: true
# memory_reservation: 2048m
- name: elasticsearch
image: solita/ubuntu-systemd:bionic
command: /sbin/init
ulimits:
- nofile:262144:262144
privileged: true
memory_reservation: 2048m
#- name: xenial
# image: solita/ubuntu-systemd:xenial
# privileged: true
@ -35,12 +36,12 @@ platforms:
# memory_reservation: 2048m
# ulimits:
# - nofile:262144:262144
- name: centos7
image: milcom/centos7-systemd
memory_reservation: 2048m
privileged: true
ulimits:
- nofile:262144:262144
#- name: centos7
# image: milcom/centos7-systemd
# memory_reservation: 2048m
# privileged: true
# ulimits:
# - nofile:262144:262144
provisioner:
name: ansible
playbooks:

View File

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

41
update-dnsmasq.sh Normal file
View File

@ -0,0 +1,41 @@
#!/bin/bash
# 10 seconds interval time by default
INTERVAL=${INTERVAL:-10}
# dnsmasq config directory
DNSMASQ_CONFIG=${DNSMASQ_CONFIG:-.}
# commands used in this script
DOCKER=${DOCKER:-docker}
SLEEP=${SLEEP:-sleep}
TAIL=${TAIL:-tail}
declare -A service_map
while true
do
changed=false
while read line
do
name=${line##* }
ip=$(${DOCKER} inspect --format '{{.NetworkSettings.IPAddress}}' $name)
# if IP addr changed
if [ -z ${service_map[$name]} ] || [ ${service_map[$name]} != $ip ]
then
service_map[$name]=$ip
# write to file
echo $name has a new IP Address $ip >&2
echo "host-record=$name,$ip" > "${DNSMASQ_CONFIG}/docker-$name"
changed=true
fi
done < <(${DOCKER} ps | ${TAIL} -n +2)
# a change of IP address occured, restart dnsmasq
if [ $changed = true ]
then
systemctl restart dnsmasq
fi
${SLEEP} $INTERVAL
done