Unable to start JBoss EAP using ansible

Hi,

I had created below ansible structure :

-rw-rw-r-- 1 packt packt 1841 Jun 3 18:36 README.md -rw-rw-r-- 1 packt packt 217 Jun 3 18:36 LICENSE.md -rw-rw-r-- 1 packt packt 123 Jul 12 17:57 ansible.cfg -rw-rw-r-- 1 packt packt 103 Jul 12 17:58 site.yml drwxrwxr-x 2 packt packt 4096 Jul 13 05:05 group_vars drwxrwxr-x 4 packt packt 4096 Jul 13 05:06 roles -rw-rw-r-- 1 packt packt 428 Jul 17 05:23 inventory

Below is my main.yml under roles/jboss/

— - name: For ubuntu download the JDK1.7, Jboss software get_url: url=https://s3.ap-south-1.amazonaws.com/shivasoftware/{‌{item}} dest=/home/packt mode=0755 with_items: - eap64.tar.gz - jdk-7u80-linux-x64.tar.gz

  • name: extract the JDK Software command: chdir=/home/packt /bin/tar -xvf /home/packt/{‌{item}} with_items: - eap64.tar.gz - jdk-7u80-linux-x64.tar.gz

  • name: setting JAVA_HOME after taking the backkup of .bashrc blockinfile: path: /home/packt/.bashrc block: | export JAVA_HOME=/home/packt/jdk1.7.0_80 export PATH=$JAVA_HOME/bin:$PATH insertafter: EOF backup: yes # become: yes

  • name: source bashrc shell: . /home/packt/.bashrc register: home_java

  • name: start JBoss command: /home/packt/EAP-6.4.0/bin/standalone.sh # when: echo JAVA_HOME != /home/packt/jdk1.7.0_80 when: home_java.stdout.find(‘java’) == -1 When i’m executing the playbook I’m getting the below issue:

TASK [Gathering Facts] *************************************************************************************************************** ok: [ubuntu3]

TASK [ubuntu : For ubuntu download the JDK1.7, Jboss software] *********************************************************************** ok: [ubuntu3] => (item=eap64.tar.gz) ok: [ubuntu3] => (item=jdk-7u80-linux-x64.tar.gz)

TASK [ubuntu : extract the JDK Software] ********************************************************************************************* changed: [ubuntu3] => (item=eap64.tar.gz) changed: [ubuntu3] => (item=jdk-7u80-linux-x64.tar.gz)

TASK [ubuntu : setting JAVA_HOME after taking the backkup of .bashrc] **************************************************************** ok: [ubuntu3]

TASK [ubuntu : source bashrc] ******************************************************************************************************** changed: [ubuntu3]

TASK [ubuntu : start JBoss] ********************************************************************************************************** fatal: [ubuntu3]: FAILED! => {“changed”: true, “cmd”: [“/home/packt/EAP-6.4.0/bin/standalone.sh”], “delta”: “0:00:00.277796”, “end”: “2018-07-17 06:06:42.393817”, “msg”: “non-zero return code”, “rc”: 127, “start”: “2018-07-17 06:06:42.116021”, “stderr”: “/home/packt/EAP-6.4.0/bin/standalone.sh: 1: eval: java: not found”, “stderr_lines”: [“/home/packt/EAP-6.4.0/bin/standalone.sh: 1: eval: java: not found”], “stdout”: “=========================================================================\n\n JBoss Bootstrap Environment\n\n JBOSS_HOME: /home/packt/EAP-6.4.0\n\n JAVA: java\n\n JAVA_OPTS: -server -Xms1303m -Xmx1303m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Djboss.modules.policy-permissions=true\n\n=========================================================================”, “stdout_lines”: [“=========================================================================”, “”, " JBoss Bootstrap Environment", “”, " JBOSS_HOME: /home/packt/EAP-6.4.0", “”, " JAVA: java", “”, " JAVA_OPTS: -server -Xms1303m -Xmx1303m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Djboss.modules.policy-permissions=true", “”, “=========================================================================”]} to retry, use: --limit @/home/packt/ansible/site.retry

PLAY RECAP *************************************************************************************************************************** ubuntu3 : ok=5 changed=2 unreachable=0 failed=1

Can you help me to resolve the issue??

When I was checking in client machine,

  1. which java gave me below response: /home/packt/jdk1.7.0_80/bin/java

  2. structure created on target machine:

drwxr-xr-x 8 packt packt 4096 Apr 11 2015 jdk1.7.0_80 -rw-r–r-- 1 packt packt 220 Nov 14 2017 .bash_logout drwxr-xr-x 3 root root 4096 Nov 14 2017 … -rw-r–r-- 1 packt packt 655 Nov 14 2017 .profile drwx------ 2 packt packt 4096 Nov 14 2017 .cache -rw-r–r-- 1 packt packt 0 Nov 14 2017 .sudo_as_admin_successful drwx------ 2 packt packt 4096 Jul 14 04:40 .ssh -rw------- 1 packt packt 0 Jul 17 03:40 .bash_history drwx------ 3 packt packt 4096 Jul 17 03:47 .ansible -rwxr-xr-x 1 packt packt 3771 Jul 17 05:00 .bashrc.2588.2018-07-17@05:02:12~ -rwxr-xr-x 1 packt packt 3903 Jul 17 05:02 .bashrc.3982.2018-07-17@05:36:18~ -rwxr-xr-x 1 packt packt 3907 Jul 17 05:36 .bashrc.4253.2018-07-17@05:42:37~ -rw------- 1 packt packt 3368 Jul 17 05:38 .viminfo -rwxr-xr-x 1 packt packt 3903 Jul 17 05:42 .bashrc -rw-rw-r-- 1 packt packt 173414400 Jul 17 05:42 eap.tar -rwxr-xr-x 1 packt packt 153530841 Jul 17 05:45 jdk-7u80-linux-x64.tar.gz -rwxr-xr-x 1 packt packt 151761793 Jul 17 05:47 eap64.tar.gz drwxr-xr-x 7 packt packt 4096 Jul 17 05:48 . drwxrwxr-x 13 packt packt 4096 Jul 17 06:06 EAP-6.4.0

Hi, Shankar Shiva
Can you make correct formating?
Not sure what did you mean here - " when: echo JAVA_HOME != /home/packt/jdk1.7.0_80 when: home_java.stdout.find(‘java’) == -1"

Hmm, by the look of things you are trying to use ‘command’ to actually start jboss.

This is unlikely to work well as you have no shell when using ‘command’, meaning no shell features like environment varirables or > or &

You can try and use ‘environment’ keyword to specify exact environment variables you need to run the command (see https://docs.ansible.com/ansible/latest/user_guide/playbooks_environment.html?highlight=environment#working-with-language-specific-version-managers for examples) , but I think you will wind up with more readable playbooks if you create a service script to run jboss.

The service script can su to the correct user and set up any environment variables that jboss needs before starting the java command line.

Then, once you have a service set up you can use service module to start stop jboss. All the complexity of starting up jboss is hidden away in the service startup script and your playbooks intentions become easier to understand.

Hope this helps,

Jon

Hi,
Thanks for your reply. Below is reconstructed problem statement. Also, PFA
files I used

Problem Statement:
I'm using ansible roles to install and start JBoss EAP 6.4 version. As
part of this:
1) I'm downloading and extracting the JDK and EAP.tar.gz from S3
2) Once done I'm updating the JDK in user profile folder for setting tehe
class path
3) Lastly starting the jboss application server

But, I'm getting the below exception when running the playbook:
FAILED! => {"changed": true, "cmd":
["/home/packt/EAP-6.4.0/bin/standalone.sh"], "delta": "0:00:00.277796",
"end": "2018-07-17 06:06:42.393817", "msg": "non-zero return code", "rc":
127, "start": "2018-07-17 06:06:42.116021", "stderr":
"/home/packt/EAP-6.4.0/bin/standalone.sh: 1: eval: java: not found",
"stderr_lines": ["/home/packt/EAP-6.4.0/bin/standalone.sh: 1: eval: java:
not found"], "stdout":
"=========================================================================\n\n
JBoss Bootstrap Environment\n\n JBOSS_HOME: /home/packt/EAP-6.4.0\n\n
JAVA: java\n\n JAVA_OPTS: -server -Xms1303m -Xmx1303m
-XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=false
-Djava.net.preferIPv6Addresses=true
-Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true
-Djboss.modules.policy-permissions=true\n\n=========================================================================",
"stdout_lines":
["=========================================================================",
"", " JBoss Bootstrap Environment", "", " JBOSS_HOME:
/home/packt/EAP-6.4.0", "", " JAVA: java", "", " JAVA_OPTS: -server
-Xms1303m -Xmx1303m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=false
-Djava.net.preferIPv6Addresses=true
-Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true
-Djboss.modules.policy-permissions=true", "",
"========================================================================="]}
       to retry, use: --limit @/home/packt/ansible/site.retry

But, on the client machine when I start the JBoss application server I'm
able to start and not getting the exception.

Thanks and Regards,
Shankar

(attachments)

ansible.zip (4.34 KB)

Hi,
Now it’s more clear :slight_smile:
ansible/roles/ubuntu/tasks/main.yml

  • name: start JBoss
    command: source /home/packt/.bashrc; /home/packt/EAP-6.4.0/bin/domain.sh

Try this way.
In your variant you just launch bashrc in one process and then launch jboss in the other. But the processes are different, and one can’t access the variables from another.

ср, 18 июл. 2018 г. в 20:48, Shankar Shiva <mailnsa@gmail.com>:

Tried but no luck :unamused:

ok, and what if specify the variable in command module itself?
command: /home/packt/EAP-6.4.0/bin/domain.sh

environment:

JAVA_HOME: …

(see here - https://docs.ansible.com/ansible/2.6/user_guide/playbooks_environment.html)

чт, 19 июл. 2018 г. в 14:09, Shankar Shiva <mailnsa@gmail.com>: