From 1359081e84b39d3a0c016e8547fdd81c576b2f00 Mon Sep 17 00:00:00 2001 From: Laurent Hoss Date: Mon, 8 Aug 2016 09:12:49 +0200 Subject: [PATCH] Refactor into reusable includes (#33) * refactor to re-use redhat tasks for new debian install * refactor tasks into reusable includes * removed extra lines --- tasks/RedHat.yml | 58 +++-------------------------------------------- tasks/systemd.yml | 10 ++++++++ tasks/tarball.yml | 38 +++++++++++++++++++++++++++++++ tasks/upstart.yml | 10 ++++++++ 4 files changed, 61 insertions(+), 55 deletions(-) create mode 100644 tasks/systemd.yml create mode 100644 tasks/tarball.yml create mode 100644 tasks/upstart.yml diff --git a/tasks/RedHat.yml b/tasks/RedHat.yml index 06691a5..ffa145f 100644 --- a/tasks/RedHat.yml +++ b/tasks/RedHat.yml @@ -1,68 +1,16 @@ --- -- file: path=/opt/src state=directory -- file: path={{zookeeper_dir}} state=directory - -- name: Download zookeeper version. - get_url: url={{zookeeper_url}} dest=/opt/src/zookeeper-{{zookeeper_version}}.tar.gz - tags: bootstrap - - name: Install OS Packages yum: name={{ item }} state=present with_items: - libselinux-python -- name: Unpack tarball. - command: tar zxf /opt/src/zookeeper-{{zookeeper_version}}.tar.gz --strip-components=1 chdir={{zookeeper_dir}} creates={{zookeeper_dir}}/bin - tags: bootstrap - -- group: name=zookeeper system=yes -- user: name=zookeeper group=zookeeper system=yes - -- name: Change ownership on zookeeper directory. - file: path={{zookeeper_dir}} state=directory owner=zookeeper group=zookeeper recurse=yes - tags: bootstrap - -- name: Create zookeeper data folder. - file: path={{data_dir}} state=directory recurse=yes owner=zookeeper group=zookeeper - tags: bootstrap - -- name: Create zookeeper logs folder. - file: path={{log_dir}} state=directory recurse=yes owner=zookeeper group=zookeeper - tags: bootstrap - -- name: Check if /etc/init exists - stat: path=/etc/init/ - register: etc_init - -- name: Upstart script. - template: src=zookeeper.conf.j2 dest=/etc/init/zookeeper.conf - when: etc_init.stat.exists == true - tags: deploy - notify: - - Restart zookeeper - -- name: Check if systemd exists - stat: path=/usr/lib/systemd/system/ - register: systemd_check - -- name: Systemd script. - template: src=zookeeper.service.j2 dest=/usr/lib/systemd/system/zookeeper.service - when: systemd_check.stat.exists == true - tags: deploy - notify: - - Restart zookeeper +- include: tarball.yml -- name: Write myid file. - template: src=myid.j2 dest={{data_dir}}/myid owner=zookeeper group=zookeeper +- include: upstart.yml tags: deploy - notify: - - Restart zookeeper -- name: Configure zookeeper - template: src=zoo.cfg.j2 dest={{ zookeeper_dir }}/conf/zoo.cfg owner=zookeeper group=zookeeper +- include: systemd.yml tags: deploy - notify: - - Restart zookeeper - name: Start zookeeper service: name=zookeeper state=started enabled=yes diff --git a/tasks/systemd.yml b/tasks/systemd.yml new file mode 100644 index 0000000..4adef10 --- /dev/null +++ b/tasks/systemd.yml @@ -0,0 +1,10 @@ +--- +- name: Check if systemd exists + stat: path=/usr/lib/systemd/system/ + register: systemd_check + +- name: Systemd script. + template: src=zookeeper.service.j2 dest=/usr/lib/systemd/system/zookeeper.service + when: systemd_check.stat.exists == true + notify: + - Restart zookeeper diff --git a/tasks/tarball.yml b/tasks/tarball.yml new file mode 100644 index 0000000..e90b1f1 --- /dev/null +++ b/tasks/tarball.yml @@ -0,0 +1,38 @@ +--- +- file: path=/opt/src state=directory +- file: path={{zookeeper_dir}} state=directory + +- name: Download zookeeper version. + get_url: url={{zookeeper_url}} dest=/opt/src/zookeeper-{{zookeeper_version}}.tar.gz + tags: bootstrap + +- name: Unpack tarball. + command: tar zxf /opt/src/zookeeper-{{zookeeper_version}}.tar.gz --strip-components=1 chdir={{zookeeper_dir}} creates={{zookeeper_dir}}/bin + tags: bootstrap + +- group: name=zookeeper system=yes +- user: name=zookeeper group=zookeeper system=yes + +- name: Change ownership on zookeeper directory. + file: path={{zookeeper_dir}} state=directory owner=zookeeper group=zookeeper recurse=yes + tags: bootstrap + +- name: Create zookeeper data folder. + file: path={{data_dir}} state=directory recurse=yes owner=zookeeper group=zookeeper + tags: bootstrap + +- name: Create zookeeper logs folder. + file: path={{log_dir}} state=directory recurse=yes owner=zookeeper group=zookeeper + tags: bootstrap + +- name: Write myid file. + template: src=myid.j2 dest={{data_dir}}/myid owner=zookeeper group=zookeeper + tags: deploy + notify: + - Restart zookeeper + +- name: Configure zookeeper + template: src=zoo.cfg.j2 dest={{ zookeeper_dir }}/conf/zoo.cfg owner=zookeeper group=zookeeper + tags: deploy + notify: + - Restart zookeeper diff --git a/tasks/upstart.yml b/tasks/upstart.yml new file mode 100644 index 0000000..f20f982 --- /dev/null +++ b/tasks/upstart.yml @@ -0,0 +1,10 @@ +--- +- name: Check if /etc/init exists + stat: path=/etc/init/ + register: etc_init + +- name: Upstart script. + template: src=zookeeper.conf.j2 dest=/etc/init/zookeeper.conf + when: etc_init.stat.exists == true + notify: + - Restart zookeeper