Commit 2b91fd39 2b91fd39234c2b271c68c35273b57480d184e333 by Khaled

new file: deploy.sh

	new file:   inventories/inventory.yml
	new file:   playbooks/zookeeper.yml
	new file:   roles/zookeeper/README.md
	new file:   roles/zookeeper/defaults/main.yml
	new file:   roles/zookeeper/handlers/main.yml
	new file:   roles/zookeeper/meta/main.yml
	new file:   roles/zookeeper/tasks/config.yml
	new file:   roles/zookeeper/tasks/install_zookeeper.yml
	new file:   roles/zookeeper/tasks/java_install.yml
	new file:   roles/zookeeper/tasks/main.yml
	new file:   roles/zookeeper/tasks/user.yml
	new file:   roles/zookeeper/templates/configzk.j2
	new file:   roles/zookeeper/templates/myid.j2
	new file:   roles/zookeeper/tests/inventory
	new file:   roles/zookeeper/tests/test.yml
	new file:   roles/zookeeper/vars/main.yml
0 parents
#!/bin/bash
############################################################
#
# Description : déploiement à la volée de conteneur docker
#
# Auteur : Xavier
#
# Date : 28/12/2018
#
###########################################################
#si option --create
if [ "$1" == "--create" ];then
# définition du nombre de conteneur
nb_machine=1
[ "$2" != "" ] && nb_machine=$2
# setting min/max
min=1
max=0
# récupération de idmax
idmax=`docker ps -a --format '{{ .Names}}' | awk -F "-" -v user="kherzi" '$0 ~ user"-alpine" {print $3}' | sort -r |head -1`
# redéfinition de min et max
min=$(($idmax + 1))
max=$(($idmax + $nb_machine))
# lancement des conteneurs
for i in $(seq $min $max);do
docker run -tid --cap-add NET_ADMIN --cap-add SYS_ADMIN --publish-all=true -v /srv/data:/srv/html -v /sys/fs/cgroup:/sys/fs/cgroup:ro --name kherzi-debian-$i -h kherzi-debian-$i khaledherzi/debian-server
docker exec -ti kherzi-debian-$i /bin/sh -c "useradd -m -p test123 kherzi"
docker exec -ti kherzi-debian-$i /bin/sh -c "mkdir /home/kherzi/.ssh && chmod 700 /home/kherzi/.ssh && chown kherzi:kherzi /home/kherzi/.ssh"
docker cp /home/kherzi/.ssh/id_rsa.pub kherzi-debian-$i:/home/kherzi/.ssh/authorized_keys
docker exec -ti kherzi-debian-$i /bin/sh -c "chmod 600 /home/kherzi/.ssh/authorized_keys && chown kherzi:kherzi /home/kherzi/.ssh/authorized_keys"
docker exec -ti kherzi-debian-$i /bin/sh -c "echo 'kherzi ALL=(ALL) NOPASSWD: ALL'>>/etc/sudoers"
docker exec -ti kherzi-debian-$i /bin/sh -c "service ssh start"
echo "Conteneur kherzi-debian-$i créé"
done
# si option --drop
elif [ "$1" == "--drop" ];then
echo "Suppression des conteneurs..."
docker rm -f $(docker ps -a | grep kherzi-debian | awk '{print $1}')
echo "Fin de la suppression"
# si option --start
elif [ "$1" == "--start" ];then
echo ""
docker start $(docker ps -a | grep kherzi-debian | awk '{print $1}')
echo ""
# si option --ansible
elif [ "$1" == "--ansible" ];then
echo ""
echo " notre option est --ansible"
echo ""
# si option --infos
elif [ "$1" == "--infos" ];then
echo ""
echo "Informations des conteneurs : "
echo ""
for conteneur in $(docker ps -a | grep kherzi-debian | awk '{print $1}');do
docker inspect -f ' => {{.Name}} - {{.NetworkSettings.IPAddress }}' $conteneur
done
echo ""
# si aucune option affichage de l'aide
else
echo "
Options :
- --create : lancer des conteneurs
- --drop : supprimer les conteneurs créer par le deploy.sh
- --infos : caractéristiques des conteneurs (ip, nom, user...)
- --start : redémarrage des conteneurs
- --ansible : déploiement arborescence ansible
"
fi
---
all:
children:
common:
children:
zookeepernodes:
hosts:
znode1:
ansible_host: 172.17.0.2
\ No newline at end of file
---
- name: install zookeeper
hosts: znode1
become: yes
roles:
- ./roles/zookeeper
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
---
myid1: 1
tickTime: 2000
initLimit: 10
syncLimit: 5
dataDir: /data/zookeeper
clientPort: 2181
serv1: 172.17.0.2:2888:3888
\ No newline at end of file
---
# handlers file for roles/zookeeper
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
- name: zookeeper configs
template:
src: ./templates/configzk.j2
dest: /etc/zookeeper/conf/zoo.cfg
- name: create the directory of the node
file:
path: /data/zookeeper
state: directory
recurse: yes
owner: zookeeper
group:
- name: create the file of the id of the node
template:
src: ./templates/myid.j2
dest: /data/zookeeper/myid
owner: zookeeper
group: zookeeper
mode: 0700
- name: install zookeeper
apt:
name: zookeeperd
state: present
- name: install JRE
apt:
name: default-jre
autoclean: yes
cache_valid_time: 3600
- name: Download JDK binaries
get_url:
url: https://download.oracle.com/java/18/archive/jdk-18.0.2.1_linux-aarch64_bin.tar.gz
dest: /opt/jdk-18.0.2.1_linux-aarch64_bin.tar.gz
- name: unzip the downloaded jdk
unarchive:
src: /opt/jdk-18.0.2.1_linux-aarch64_bin.tar.gz
dest: /opt
remote_src: yes
- name: set the java home in /etc/profile file
lineinfile:
path: /etc/profile
state: present
line: "{{item}}"
with_items:
- 'export JAVA_HOME="/opt/jdk-18.0.2.1"'
- 'export PATH=$JAVA_HOME/bin'
- include_tasks: "user.yml"
- include_tasks: "java_install.yml"
- include_tasks: "install_zookeeper.yml"
- include_tasks: "config.yml"
\ No newline at end of file
- name: create zookeeper group
group:
name: zookeeper
- name: create user for zookeeper
user:
name: zookeeper
groups: zookeeper
password: "{'password' | password_hash('sha512')}"
register: __user__zk
\ No newline at end of file
tickTime= {{tickTime}}
initLimit= {{initLimit}}
syncLimit= {{syncLimit}}
dataDir= {{dataDir}}
clientPort= {{clientPort}}
server.1= {{serv1}}
\ No newline at end of file
---
- hosts: localhost
remote_user: root
roles:
- roles/zookeeper