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
1 #!/bin/bash
2
3 ############################################################
4 #
5 # Description : déploiement à la volée de conteneur docker
6 #
7 # Auteur : Xavier
8 #
9 # Date : 28/12/2018
10 #
11 ###########################################################
12
13
14
15
16 #si option --create
17 if [ "$1" == "--create" ];then
18
19 # définition du nombre de conteneur
20 nb_machine=1
21 [ "$2" != "" ] && nb_machine=$2
22
23 # setting min/max
24 min=1
25 max=0
26
27 # récupération de idmax
28 idmax=`docker ps -a --format '{{ .Names}}' | awk -F "-" -v user="kherzi" '$0 ~ user"-alpine" {print $3}' | sort -r |head -1`
29
30 # redéfinition de min et max
31 min=$(($idmax + 1))
32 max=$(($idmax + $nb_machine))
33
34 # lancement des conteneurs
35 for i in $(seq $min $max);do
36 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
37 docker exec -ti kherzi-debian-$i /bin/sh -c "useradd -m -p test123 kherzi"
38 docker exec -ti kherzi-debian-$i /bin/sh -c "mkdir /home/kherzi/.ssh && chmod 700 /home/kherzi/.ssh && chown kherzi:kherzi /home/kherzi/.ssh"
39 docker cp /home/kherzi/.ssh/id_rsa.pub kherzi-debian-$i:/home/kherzi/.ssh/authorized_keys
40 docker exec -ti kherzi-debian-$i /bin/sh -c "chmod 600 /home/kherzi/.ssh/authorized_keys && chown kherzi:kherzi /home/kherzi/.ssh/authorized_keys"
41 docker exec -ti kherzi-debian-$i /bin/sh -c "echo 'kherzi ALL=(ALL) NOPASSWD: ALL'>>/etc/sudoers"
42 docker exec -ti kherzi-debian-$i /bin/sh -c "service ssh start"
43 echo "Conteneur kherzi-debian-$i créé"
44 done
45
46
47 # si option --drop
48 elif [ "$1" == "--drop" ];then
49
50 echo "Suppression des conteneurs..."
51 docker rm -f $(docker ps -a | grep kherzi-debian | awk '{print $1}')
52 echo "Fin de la suppression"
53
54
55 # si option --start
56 elif [ "$1" == "--start" ];then
57
58 echo ""
59 docker start $(docker ps -a | grep kherzi-debian | awk '{print $1}')
60 echo ""
61
62
63
64 # si option --ansible
65 elif [ "$1" == "--ansible" ];then
66
67 echo ""
68 echo " notre option est --ansible"
69 echo ""
70
71
72
73 # si option --infos
74 elif [ "$1" == "--infos" ];then
75
76 echo ""
77 echo "Informations des conteneurs : "
78 echo ""
79 for conteneur in $(docker ps -a | grep kherzi-debian | awk '{print $1}');do
80 docker inspect -f ' => {{.Name}} - {{.NetworkSettings.IPAddress }}' $conteneur
81 done
82 echo ""
83
84
85
86 # si aucune option affichage de l'aide
87 else
88
89 echo "
90
91 Options :
92 - --create : lancer des conteneurs
93
94 - --drop : supprimer les conteneurs créer par le deploy.sh
95
96 - --infos : caractéristiques des conteneurs (ip, nom, user...)
97
98 - --start : redémarrage des conteneurs
99
100 - --ansible : déploiement arborescence ansible
101
102 "
103
104 fi
1 ---
2 all:
3 children:
4 common:
5 children:
6 zookeepernodes:
7 hosts:
8 znode1:
9 ansible_host: 172.17.0.2
...\ No newline at end of file ...\ No newline at end of file
1 ---
2 - name: install zookeeper
3 hosts: znode1
4 become: yes
5 roles:
6 - ./roles/zookeeper
7
1 Role Name
2 =========
3
4 A brief description of the role goes here.
5
6 Requirements
7 ------------
8
9 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.
10
11 Role Variables
12 --------------
13
14 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.
15
16 Dependencies
17 ------------
18
19 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.
20
21 Example Playbook
22 ----------------
23
24 Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
25
26 - hosts: servers
27 roles:
28 - { role: username.rolename, x: 42 }
29
30 License
31 -------
32
33 BSD
34
35 Author Information
36 ------------------
37
38 An optional section for the role authors to include contact information, or a website (HTML is not allowed).
1 ---
2 myid1: 1
3
4 tickTime: 2000
5 initLimit: 10
6 syncLimit: 5
7 dataDir: /data/zookeeper
8 clientPort: 2181
9 serv1: 172.17.0.2:2888:3888
...\ No newline at end of file ...\ No newline at end of file
1 ---
2 # handlers file for roles/zookeeper
1 galaxy_info:
2 author: your name
3 description: your role description
4 company: your company (optional)
5
6 # If the issue tracker for your role is not on github, uncomment the
7 # next line and provide a value
8 # issue_tracker_url: http://example.com/issue/tracker
9
10 # Choose a valid license ID from https://spdx.org - some suggested licenses:
11 # - BSD-3-Clause (default)
12 # - MIT
13 # - GPL-2.0-or-later
14 # - GPL-3.0-only
15 # - Apache-2.0
16 # - CC-BY-4.0
17 license: license (GPL-2.0-or-later, MIT, etc)
18
19 min_ansible_version: 2.1
20
21 # If this a Container Enabled role, provide the minimum Ansible Container version.
22 # min_ansible_container_version:
23
24 #
25 # Provide a list of supported platforms, and for each platform a list of versions.
26 # If you don't wish to enumerate all versions for a particular platform, use 'all'.
27 # To view available platforms and versions (or releases), visit:
28 # https://galaxy.ansible.com/api/v1/platforms/
29 #
30 # platforms:
31 # - name: Fedora
32 # versions:
33 # - all
34 # - 25
35 # - name: SomePlatform
36 # versions:
37 # - all
38 # - 1.0
39 # - 7
40 # - 99.99
41
42 galaxy_tags: []
43 # List tags for your role here, one per line. A tag is a keyword that describes
44 # and categorizes the role. Users find roles by searching for tags. Be sure to
45 # remove the '[]' above, if you add tags to this list.
46 #
47 # NOTE: A tag is limited to a single word comprised of alphanumeric characters.
48 # Maximum 20 tags per role.
49
50 dependencies: []
51 # List your role dependencies here, one per line. Be sure to remove the '[]' above,
52 # if you add dependencies to this list.
1 - name: zookeeper configs
2 template:
3 src: ./templates/configzk.j2
4 dest: /etc/zookeeper/conf/zoo.cfg
1 - name: create the directory of the node
2 file:
3 path: /data/zookeeper
4 state: directory
5 recurse: yes
6 owner: zookeeper
7 group:
8
9
10 - name: create the file of the id of the node
11 template:
12 src: ./templates/myid.j2
13 dest: /data/zookeeper/myid
14 owner: zookeeper
15 group: zookeeper
16 mode: 0700
17
18 - name: install zookeeper
19 apt:
20 name: zookeeperd
21 state: present
22
23
1
2 - name: install JRE
3 apt:
4 name: default-jre
5 autoclean: yes
6 cache_valid_time: 3600
7
8 - name: Download JDK binaries
9 get_url:
10 url: https://download.oracle.com/java/18/archive/jdk-18.0.2.1_linux-aarch64_bin.tar.gz
11 dest: /opt/jdk-18.0.2.1_linux-aarch64_bin.tar.gz
12
13 - name: unzip the downloaded jdk
14 unarchive:
15 src: /opt/jdk-18.0.2.1_linux-aarch64_bin.tar.gz
16 dest: /opt
17 remote_src: yes
18
19 - name: set the java home in /etc/profile file
20 lineinfile:
21 path: /etc/profile
22 state: present
23 line: "{{item}}"
24 with_items:
25 - 'export JAVA_HOME="/opt/jdk-18.0.2.1"'
26 - 'export PATH=$JAVA_HOME/bin'
1
2 - include_tasks: "user.yml"
3
4 - include_tasks: "java_install.yml"
5
6 - include_tasks: "install_zookeeper.yml"
7
8 - include_tasks: "config.yml"
...\ No newline at end of file ...\ No newline at end of file
1 - name: create zookeeper group
2 group:
3 name: zookeeper
4
5
6 - name: create user for zookeeper
7 user:
8 name: zookeeper
9 groups: zookeeper
10 password: "{'password' | password_hash('sha512')}"
11 register: __user__zk
...\ No newline at end of file ...\ No newline at end of file
1
2
3 tickTime= {{tickTime}}
4 initLimit= {{initLimit}}
5 syncLimit= {{syncLimit}}
6 dataDir= {{dataDir}}
7 clientPort= {{clientPort}}
8 server.1= {{serv1}}
...\ No newline at end of file ...\ No newline at end of file
1 ---
2 - hosts: localhost
3 remote_user: root
4 roles:
5 - roles/zookeeper