diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5c08e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tests/test.sh +*.retry diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..eacd024 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +--- +services: docker + +env: +# - distro: centos7 + - distro: ubuntu1604 + +script: + # Download test shim. + - wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/ + - chmod +x ${PWD}/tests/test.sh + + # Run tests. + - ${PWD}/tests/test.sh diff --git a/README.md b/README.md index 70fca6b..b6ee493 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Ansible Role: Tomcat 8 +# Ansible Role: Tomcat 8 [![Build Status](https://travis-ci.org/Islandora-Devops/ansible-role-tomcat8.svg?branch=master)](https://travis-ci.org/Islandora-Devops/ansible-role-tomcat8) An Ansible role that installs Tomcat 8 on: @@ -47,10 +47,22 @@ tomcat8_server_user: tomcat8 tomcat8_server_group: tomcat8 ``` +Some OS-specific variables are set in vars/* but can be overridden +``` +tomcat8_home: /opt/tomcat +``` + +Including these only used by CentOS/RH +``` +tomcat8_version: 8.5.27 +tomcat_binary_url: "http://www-eu.apache.org/dist/tomcat/tomcat-8/v{{ tomcat8_version }}/bin/apache-tomcat-{{ tomcat8_version }}.tar.gz" +tomcat_target_dir: "/opt/apache-tomcat-{{ tomcat8_version }}" +``` + ## Dependencies None - + ## Example Playbook - hosts: webservers @@ -59,4 +71,4 @@ tomcat8_server_group: tomcat8 ## License -MIT \ No newline at end of file +MIT diff --git a/defaults/main.yml b/defaults/main.yml index 70ebc68..34189f1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,7 +3,7 @@ tomcat8_packages: tomcat8_admin_packages: - tomcat8-admin -tomcat8_home: /var/lib/tomcat8 +tomcat_service_name: tomcat8 tomcat8_admin_install: yes @@ -12,6 +12,7 @@ tomcat8_users: [] tomcat8_server_user: tomcat8 tomcat8_server_group: tomcat8 +tomcat8_user_home: /home/tomcat8 # The home directory of the Java development kit (JDK). You need at least # JDK version 7. If JAVA_HOME is not set, some common directories for @@ -46,3 +47,11 @@ tomcat8_java_opts: # do not need authbind. It is used for binding Tomcat to lower port numbers. # (yes/no, default: no) #tomcat8_authbind: no + +# Some OS-specific variables are set in vars/* but can be overridden here: +# tomcat8_home: /opt/tomcat +# +# Tomcat binary to dl and related path (For installing binaries on CentOS/RH) +# tomcat8_version: 8.5.27 +# tomcat_binary_url: "http://www-eu.apache.org/dist/tomcat/tomcat-8/v{{ tomcat8_version }}/bin/apache-tomcat-{{ tomcat8_version }}.tar.gz" +# tomcat_target_dir: "/opt/apache-tomcat-{{ tomcat8_version }}" diff --git a/tasks/config.yml b/tasks/config.yml index 59c765d..a9d1730 100644 --- a/tasks/config.yml +++ b/tasks/config.yml @@ -1,16 +1,38 @@ --- +- name: template /etc/default/tomcat8 + template: + src: tomcat-defaults.j2 + dest: /etc/default/tomcat8 + notify: restart tomcat8 + when: ansible_os_family == 'Debian' + +- name: template {{tomcat8_home}}/bin/setenv.sh + template: + src: setenv.sh.j2 + dest: "{{tomcat8_home}}/bin/setenv.sh" + notify: restart tomcat8 + when: ansible_os_family == 'RedHat' + +- name: server configuration + template: + src: server.xml.j2 + dest: "{{tomcat8_home}}/conf/server.xml" + notify: restart tomcat8 + sudo: True + - name: template tomcat-users.xml template: src: tomcat-users.xml.j2 - dest: /etc/tomcat8/tomcat-users.xml - owner: "root" + dest: "{{tomcat8_home}}/conf/tomcat-users.xml" + owner: "{{ tomcat8_server_user }}" group: "{{ tomcat8_server_group }}" mode: "640" notify: restart tomcat8 -- name: template /etc/default/tomcat8 - template: - src: tomcat-defaults.j2 - dest: /etc/default/tomcat8 - notify: restart tomcat8 +- name: start tomcat + service: + name: "{{tomcat_service_name}}" + state: started + enabled: yes + sudo: True diff --git a/tasks/install.yml b/tasks/install-Debian.yml similarity index 82% rename from tasks/install.yml rename to tasks/install-Debian.yml index fa40fa9..fd1307d 100644 --- a/tasks/install.yml +++ b/tasks/install-Debian.yml @@ -14,3 +14,8 @@ cache_valid_time: 3600 with_items: "{{ tomcat8_admin_packages }}" when: tomcat8_admin_install + +- name: start tomcat8 + service: + name: tomcat8 + state: started diff --git a/tasks/install-RedHat.yml b/tasks/install-RedHat.yml new file mode 100644 index 0000000..dfede51 --- /dev/null +++ b/tasks/install-RedHat.yml @@ -0,0 +1,43 @@ +--- + +- name: group add + group: + name: "{{ tomcat8_server_group }}" + sudo: True + + +- name: user add + user: + name: "{{ tomcat8_server_user }}" + group: "{{ tomcat8_server_group }}" + home: "{{ tomcat8_user_home }}" + createhome: no + sudo: True + +- name: download and extract + unarchive: + src: "{{ tomcat_binary_url }}" + dest: "/opt/" + remote_src: yes + sudo: True + +- name: symlink install directory + file: + src: "{{ tomcat_target_dir }}" + path: "{{ tomcat8_home }}" + state: link + sudo: True + +- name: change ownership of target installation + file: + path: "{{ tomcat_target_dir }}" + owner: "{{ tomcat8_server_user }}" + group: "{{ tomcat8_server_group }}" + state: directory + recurse: yes + sudo: True + +- name: systemd + template: src=tomcat.service.j2 dest=/etc/systemd/system/tomcat8.service + notify: restart tomcat8 + sudo: True diff --git a/tasks/main.yml b/tasks/main.yml index ae5e3c2..abb0bd3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,11 +1,42 @@ --- -- include: install.yml +# Include variables and define needed variables. +- name: Include OS-specific variables. + include_vars: "{{ ansible_os_family }}.yml" + +- name: Define tomcat8_home + set_fact: + tomcat8_home: "{{ __tomcat8_home }}" + when: tomcat8_home is not defined + +- name: Define tomcat8_version + set_fact: + tomcat8_version: "{{ __tomcat8_version }}" + when: + - tomcat8_version is not defined + - __tomcat8_version is defined + +- name: Define tomcat_binary_url + set_fact: + tomcat_binary_url: "{{ __tomcat_binary_url }}" + when: + - tomcat_binary_url is not defined + - __tomcat_binary_url is defined + +- name: Define tomcat_target_dir + set_fact: + tomcat_target_dir: "{{ __tomcat_target_dir }}" + when: + - tomcat_target_dir is not defined + - __tomcat_target_dir is defined + +- include: "install-{{ ansible_os_family }}.yml" tags: - tomcat8 - tomcat8-install - include: config.yml + static: no tags: - tomcat8 - tomcat8-config diff --git a/templates/server.xml.j2 b/templates/server.xml.j2 new file mode 100644 index 0000000..eb7dad7 --- /dev/null +++ b/templates/server.xml.j2 @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/setenv.sh.j2 b/templates/setenv.sh.j2 new file mode 100644 index 0000000..e7f942c --- /dev/null +++ b/templates/setenv.sh.j2 @@ -0,0 +1,3 @@ +#!/bin/sh + +export JAVA_OPTS="$JAVA_OPTS {{ tomcat8_java_opts|join(' ') }}" diff --git a/templates/tomcat.service.j2 b/templates/tomcat.service.j2 new file mode 100644 index 0000000..4ce08bb --- /dev/null +++ b/templates/tomcat.service.j2 @@ -0,0 +1,21 @@ +[Unit] +Description={{ tomcat_service_name }} +After=network.target + +[Service] +Type=forking +User={{ tomcat8_server_user }} +Group={{ tomcat8_server_group }} + +Environment=CATALINA_PID={{ tomcat8_home }}/{{ tomcat_service_name }}.pid +Environment=TOMCAT_JAVA_HOME=/usr/java/default +Environment=CATALINA_HOME={{ tomcat8_home }} +Environment=CATALINA_BASE={{ tomcat8_home }} +Environment=CATALINA_OPTS= +Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -Xms512m -Xmx512m" + +ExecStart={{ tomcat8_home }}/bin/startup.sh +ExecStop=/bin/kill -15 $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..3646ff4 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: all + + roles: + - role_under_test diff --git a/vars/Debian.yml b/vars/Debian.yml new file mode 100644 index 0000000..18dd9e5 --- /dev/null +++ b/vars/Debian.yml @@ -0,0 +1 @@ +__tomcat8_home: /var/lib/tomcat8 diff --git a/vars/RedHat.yml b/vars/RedHat.yml new file mode 100644 index 0000000..ac77349 --- /dev/null +++ b/vars/RedHat.yml @@ -0,0 +1,6 @@ +__tomcat8_home: /opt/tomcat + +# Tomcat binary to dl and related path +__tomcat8_version: 8.5.28 +__tomcat_binary_url: "https://archive.apache.org/dist/tomcat/tomcat-8/v{{ tomcat8_version }}/bin/apache-tomcat-{{ tomcat8_version }}.tar.gz" +__tomcat_target_dir: "/opt/apache-tomcat-{{ tomcat8_version }}"