# Start tomcat

**URL:** <https://forum.ansible.com/t/start-tomcat/20855>\
**Category:** Ansible Developer\
**Created:** [March 14, 2016, 1:15am UTC](https://forum.ansible.com/t/start-tomcat/20855 "2016-03-14T01:15:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![GBANE\_FETIGUE](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@GBANE\_FETIGUE](https://forum.ansible.com/u/GBANE_FETIGUE)\
**Post date:** [March 14, 2016, 1:15am UTC](https://forum.ansible.com/t/start-tomcat/20855/1 "2016-03-14T01:15:45Z")

</div>

Hi folks,

Is anybody has an idea how can i resolve that error message?

TASK [tomcat : copy mmc.war to webapps] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [webserver1]

TASK [tomcat : Set Java\_opts for tomcat] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [webserver1]

TASK [tomcat : install Tomcat init script] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [webserver1]

TASK [tomcat : Start Tomcat] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [webserver1]

TASK [tomcat : wait for tomcat to start] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [webserver1]: FAILED! =\> {“changed”: false, “elapsed”: 30, “failed”: true, “msg”: “Timeout when waiting for 127.0.0.1:8080”}

NO MORE HOSTS LEFT \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @mmc.retry

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
webserver1 : ok=13 changed=1 unreachable=0 failed=1

any suggestion ??

---

<div class="post-metadata">

**Author:** ![Rene\_Moser](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Rene\_Moser](https://forum.ansible.com/u/Rene_Moser)\
**Post date:** [March 14, 2016, 6:47am UTC](https://forum.ansible.com/t/start-tomcat/20855/2 "2016-03-14T06:47:58Z")

</div>

Hi

> TASK [tomcat : wait for tomcat to start]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [webserver1]: FAILED! =\> {"changed": false, "elapsed": 30,  
> "failed": true, "msg": "Timeout when waiting for 127.0.0.1:8080"}

You didn't share the playbook so I can just guess this task is done with  
wait\_for, right?

It seems you defined the timeout to 30 seconds, increasing this timeout  
to a more appropriate value could solve this issue. If you remove the  
timeout argument, the default would be 300 sec. Find more docs and  
examples on [http://docs.ansible.com/ansible/wait\_for\_module.html](http://docs.ansible.com/ansible/wait_for_module.html)

- wait\_for:  
&nbsp;&nbsp;&nbsp;&nbsp;port: 8080  
&nbsp;&nbsp;&nbsp;&nbsp;timeout: 60

Regards  
René

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [March 14, 2016, 11:50am UTC](https://forum.ansible.com/t/start-tomcat/20855/3 "2016-03-14T11:50:38Z")

</div>

Since this is tomcat I would recommend inserting a pause before your use wait\_for as tomcat seems to come up, grab the port, do a lot of stuff and then only start listening on the port once it has deployed any wars inside it. This messes up wait\_for as it can’t make sense out of the locked port.

I set a different pause interval according the environment I am running in so the pause period doesn’t have to be unnecessarily long.  
I usually use a value which is a few seconds long than it takes for the message ‘Server startup in …’ to appear in the tomcat stderr logging.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![GBANE\_FETIGUE](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@GBANE\_FETIGUE](https://forum.ansible.com/u/GBANE_FETIGUE)\
**Post date:** [March 14, 2016, 2:16pm UTC](https://forum.ansible.com/t/start-tomcat/20855/4 "2016-03-14T14:16:38Z")

</div>

name: Install Java 1.7  
apt: name=openjdk-7-jdk state=present update\_cache=true

- name: add group Tomcat  
group: name=tomcat state=present

- name: add Tomcat User  
user: name=tomcat group=tomcat home=/usr/share/tomcat createhome=no  
sudo: True

- name: Download Tomcat  
get\_url: url=[http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.1/bin/apache-tomcat-8.0.1.tar.gz](http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.1/bin/apache-tomcat-8.0.1.tar.gz) dest=/opt/apache-tomcat-8.0.1.tar.gz

- name: Extract archive  
command: chdir=/usr/share /bin/tar -xvf /opt/apache-tomcat-8.0.1.tar.gz -C /opt/ creates=/opt/apache-tomcat-8.0.1

- name: Symlink Install directory  
file: src=/opt/apache-tomcat-8.0.1 path=/usr/share/tomcat state=link

- name: Configure Tomcat server  
template: src=server.xml dest=/usr/share/tomcat/conf/  
notify: restart tomcat

- name: Configure Tomcat users  
template: src=tomcat-users.xml dest=/usr/share/tomcat/conf/  
notify: restart tomcat

- name: copy mmc.war to webapps  
copy: src=files/mmc.war dest=/usr/share/tomcat/webapps/

- name: Set Java\_opts for tomcat  
lineinfile: dest=/opt/apache-tomcat-8.0.1/bin/setenv.sh line=‘export JAVA\_OPTS="-Xms1024M -Xmx1024M -XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=256m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true’ create=yes state=present mode=0555

- name: install Tomcat init script  
copy: src=files/tomcat-init.sh dest=/etc/init.d/tomcat mode=0755

#- name: Restart Tomcat

# command: service tomcat restart

#- name: stop Tomcat

# command: /usr/share/tomcat/bin/shutdown.sh

- name: Start Tomcat  
service: name=tomcat state=restarted enabled=yes

- name: wait for tomcat to start  
wait\_for: port=8080 delay=10

---

<div class="post-metadata">

**Author:** ![GBANE\_FETIGUE](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@GBANE\_FETIGUE](https://forum.ansible.com/u/GBANE_FETIGUE)\
**Post date:** [March 14, 2016, 2:18pm UTC](https://forum.ansible.com/t/start-tomcat/20855/5 "2016-03-14T14:18:06Z")

</div>

- name: wait for tomcat to start  
wait\_for: port=8080 delay=10

---

<div class="post-metadata">

**Author:** ![GBANE\_FETIGUE](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@GBANE\_FETIGUE](https://forum.ansible.com/u/GBANE_FETIGUE)\
**Post date:** [March 14, 2016, 2:31pm UTC](https://forum.ansible.com/t/start-tomcat/20855/6 "2016-03-14T14:31:24Z")

</div>

I posted my playbook could please look an eye on it

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [March 14, 2016, 3:20pm UTC](https://forum.ansible.com/t/start-tomcat/20855/7 "2016-03-14T15:20:06Z")

</div>

Looks good, as I said, I suggest adding something like

- name: give tomcat some time to start up

pause: seconds={{ tomcat\_startup\_delay | default(30) }}  
delegate\_to: localhost

… before your wait\_for because of the port-grabbed-but-not-yet-listening problem mentioned above.

You might want to delegate the wait\_for to localhost as well so that you are checking it is available from a remote machine too, depending on your needs.

Also I notice you have some

notify: restart\_tomcat

statements in your playbook, implying you are using a handler to restart tomcat.

I don’t use handlers myself but it possible that tomcat will be being restarted after all the steps in your playbook have completed, which you probably don’t want straight after waiting for tomcat to come back up.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![GBANE\_FETIGUE](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@GBANE\_FETIGUE](https://forum.ansible.com/u/GBANE_FETIGUE)\
**Post date:** [March 14, 2016, 3:47pm UTC](https://forum.ansible.com/t/start-tomcat/20855/8 "2016-03-14T15:47:01Z")

</div>

I would like to know

- name: give tomcat some time to start up

pause: seconds={{ tomcat\_startup\_delay | default(30) }}  
delegate\_to: localhost

need to be between the start tomcat and the wait for or complete before start tomcat ; also I want to let you know that i am testing that locally I don’t have any remote host

---

<div class="post-metadata">

**Author:** ![GBANE\_FETIGUE](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@GBANE\_FETIGUE](https://forum.ansible.com/u/GBANE_FETIGUE)\
**Post date:** [March 14, 2016, 3:55pm UTC](https://forum.ansible.com/t/start-tomcat/20855/9 "2016-03-14T15:55:34Z")

</div>

still having the same issue after adding the pause

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [March 14, 2016, 3:55pm UTC](https://forum.ansible.com/t/start-tomcat/20855/10 "2016-03-14T15:55:36Z")

</div>

Yes, my suggestion is between the start tomcat and the wait\_for

---

<div class="post-metadata">

**Author:** ![GBANE\_FETIGUE](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@GBANE\_FETIGUE](https://forum.ansible.com/u/GBANE_FETIGUE)\
**Post date:** [March 14, 2016, 4:00pm UTC](https://forum.ansible.com/t/start-tomcat/20855/11 "2016-03-14T16:00:09Z")

</div>

Yeah I tried and still not working

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [March 14, 2016, 4:04pm UTC](https://forum.ansible.com/t/start-tomcat/20855/12 "2016-03-14T16:04:56Z")

</div>

Is tomcat configured to listen on 8080 ? I notice you have a custom server.xml

are there errors in tomcat logs?

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 14, 2016, 4:06pm UTC](https://forum.ansible.com/t/start-tomcat/20855/13 "2016-03-14T16:06:45Z")

</div>

Did you ever manually check if that tomcat eventually starts?
