Tomcat Role for Windows

82 views
Skip to first unread message

akazi...@gmail.com

unread,
Nov 16, 2017, 9:46:05 AM11/16/17
to Ansible Project
Hello,

I am kind of new to ansible. I did my first steps and got the ping from my control server to a windows machine up and working. So far so good.
Now I need to install Tomcat from scratch and add later on some patches. I was in the hope to find some example roles on ansible-galaxy but there are non for Tomcat on  Windows.
So here is my question, does any one know w source for such a role which I can use as a base to develop upon? 

Thank you very much
Michael
Message has been deleted

J Hawkesworth

unread,
Nov 16, 2017, 12:43:58 PM11/16/17
to Ansible Project
This is a bit old (jdk8, tomcat8) and has a few assumptions which might not be true for your environment (the jdk and tomcat installers are kept on a web server refered to as {{build_server}}.  Its two roles one for the jdk and one for tomcat.

Definitely some things could be improved - likely you don't need a jdk, only a JRE for a start.  The service restart might not be correct and might be better as a handler anyway.

Hopefully this is enough to get you started though.

Jon


$
:~/roles/win-jdk$ tree -A
.
├── defaults
  └── main.yml
└── tasks
   
└── main.yml

2 directories, 2 files
$
:~/roles/win-jdk$ cat defaults/main.yml
---
java_major_version
: 8
java_minor_version
: 73
java_product_id
: "{64A3A4F4-B792-11D6-A78A-00B0D0180730}"
$
:~/roles/win-jdk$ cat tasks/main.yml
---
# file: roles/win-jdk/tasks/main.yml

# this role adds java to a server.  

# see ../defaults/main.yml for the default versions used
# the defaults can be overriden by setting vars in the playbook, inventory or groups

- name: fetch java if needed
  win_get_url
: url="{{ build_server }}jdk-{{ java_major_version }}u{{ java_minor_version }}-windows-x64.exe" dest="{{ win_deploy_dir }}jdk-{{ java_major_version }}u{{ java_minor_version }}-windows-x64.exe" force=no

- name: ensure java installed
  win_package
:
    name
: "Java SE Development Kit {{ java_major_version }} Update {{ java_minor_version }} (64-bit)"
    path
: "{{ win_deploy_dir }}jdk-{{ java_major_version }}u{{ java_minor_version }}-windows-x64.exe"
    product_id
: "{{ java_product_id }}"
    state
: present
    arguments
: INSTALL_SILENT=1 AUTO_UPDATE=0 WEB_JAVA=0 WEB_ANALYTICS=0 /s /L C:\deployment\log\java-installation.log
# added install options based on options here: http://docs.oracle.com/javase/8/docs/technotes/guides/install/config.html#table_config_file_options


win
-tomcat8$ cat defaults/main.yml
---
tomcat_home
: C:\Tomcat8
tomcat_installer
: apache-tomcat-8.0.35.exe

$
:~roles/win-tomcat8$ cat tasks/main.yml
---
# file: roles/win-tomcat8/tasks/main.yml
# this role adds tomcat 8 if not present
# It also removes default webapps from the installed tomcat 8
# tomcat_home is now picked up from ../defaults/main.yml

- name: fetch tomcat
  win_get_url
: url="{{ build_server }}{{ item }}" dest="{{ win_deploy_dir }}{{ item }}" force=no
  with_items
:
     
- "{{tomcat_installer }}"

- name: check for existence of latest tomcat
  win_stat
:
    path
: "{{ tomcat_home }}"
 
register: current_tomcat
 
 
- name: install tomcat if needed
  win_shell
: '{{ win_deploy_dir }}{{ tomcat_installer }} /S /D={{ tomcat_home }}'
 
when: current_tomcat.stat.exists == false

- name: remove unwanted webapps ROOT manager docs from tomcat
  win_file
: 'state=absent path={{ tomcat_home }}\webapps\{{item}}'
  with_items
:
   
- ROOT
   
- manager
   
- docs

- name: set tomcat parameters for startup
  win_shell
: '{{ tomcat_home }}\bin\tomcat8.exe update --Startup=auto --JvmMs=2000 --JvmMx=2000 --JvmOptions="-Dcatalina.home={{ tomcat_home }}\;-Dcatalina.base={{ tomcat_home }}\;-Djava.endorsed.dirs={{ tomcat_home }}\endorsed;-Djava.io.tmpdir={{ tomcat_home }}\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file={{ tomcat_home }}\conf\logging.properties;-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n;-Xms1500M;-Xmx1500M;"
 
- name: restart tomcat service
  win_service:
    name: '
Tomcat 8'
    start_mode: auto
    state: restarted
Reply all
Reply to author
Forward
0 new messages