ActiveMQ doesn't stop with an ansible role - ansible

I have a ansible role for stop an ActiveMQ server on CentOS machine
- name: " ArrĂȘt ActiveMQ"
shell: "./activemq stop"
args:
chdir: "/var/opt/application/activemq/activemq-recette/apache-activemq-5.15.9/bin/"
environment:
PATH: "{{ java_path }}:{{ ansible_env.PATH }}"
My role return failed result with this stack
changed: [192.168.108.178] => (item={'name': 'recette', 'jms_port': 61616, 'jetty_port': 8161}) => {
"ansible_loop_var": "item",
"changed": true,
"cmd": "./activemq stop",
"delta": "0:00:31.553673",
"end": "2023-01-27 09:21:32.946426",
"invocation": {
"module_args": {
"_raw_params": "./activemq stop",
"_uses_shell": true,
"argv": null,
"chdir": "/var/opt/application/activemq/activemq-recette/apache-activemq-5.15.9/bin/",
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": false
}
},
"item": {
"jetty_port": 8161,
"jms_port": 61616,
"name": "recette"
},
"msg": "",
"rc": 0,
"start": "2023-01-27 09:21:01.392753",
"stderr": "Exception in thread \"main\" java.lang.UnsupportedClassVersionError: org/apache/activemq/console/Main : Unsupported major.minor version 52.0\n\tat java.lang.ClassLoader.defineClass1(Native Method)\n\tat java.lang.ClassLoader.defineClass(ClassLoader.java:803)\n\tat java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)\n\tat java.net.URLClassLoader.defineClass(URLClassLoader.java:442)\n\tat java.net.URLClassLoader.access$100(URLClassLoader.java:64)\n\tat java.net.URLClassLoader$1.run(URLClassLoader.java:354)\n\tat java.net.URLClassLoader$1.run(URLClassLoader.java:348)\n\tat java.security.AccessController.doPrivileged(Native Method)\n\tat java.net.URLClassLoader.findClass(URLClassLoader.java:347)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:425)\n\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:312)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:358)\n\tat sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)",
"stderr_lines": [
"Exception in thread \"main\" java.lang.UnsupportedClassVersionError: org/apache/activemq/console/Main : Unsupported major.minor version 52.0",
"\tat java.lang.ClassLoader.defineClass1(Native Method)",
"\tat java.lang.ClassLoader.defineClass(ClassLoader.java:803)",
"\tat java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)",
"\tat java.net.URLClassLoader.defineClass(URLClassLoader.java:442)",
"\tat java.net.URLClassLoader.access$100(URLClassLoader.java:64)",
"\tat java.net.URLClassLoader$1.run(URLClassLoader.java:354)",
"\tat java.net.URLClassLoader$1.run(URLClassLoader.java:348)",
"\tat java.security.AccessController.doPrivileged(Native Method)",
"\tat java.net.URLClassLoader.findClass(URLClassLoader.java:347)",
"\tat java.lang.ClassLoader.loadClass(ClassLoader.java:425)",
"\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:312)",
"\tat java.lang.ClassLoader.loadClass(ClassLoader.java:358)",
"\tat sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)"
],
"stdout": "INFO: Loading '/var/opt/application/activemq/activemq-recette/apache-activemq-5.15.9//bin/env'\nINFO: Using java '/usr/bin/java'\nINFO: Waiting at least 30 seconds for regular process termination of pid '6247' : \n...............................\nINFO: Regular shutdown not successful, sending SIGKILL to process\nINFO: sending SIGKILL to pid '6247'",
"stdout_lines": [
"INFO: Loading '/var/opt/application/activemq/activemq-recette/apache-activemq-5.15.9//bin/env'",
"INFO: Using java '/usr/bin/java'",
"INFO: Waiting at least 30 seconds for regular process termination of pid '6247' : ",
"...............................",
"INFO: Regular shutdown not successful, sending SIGKILL to process",
"INFO: sending SIGKILL to pid '6247'"
]
}
The "stop command" is waiting for its end, if the role should have a special parameters for waiting it ?
It's seems that ansible role is terminate before activeMq end successful...

This message is a problem and indicates that you are running a JDK older than JDK 8. ActiveMQ 5.15.x needs JDK 8 as a minimum.
Unsupported major.minor version 52.0

Related

VirtualBox silent install via Ansible fails?

$ ansible --version
ansible 2.10.8
Per Oracle VM VirtualBox 6.1 Silent Install (How-To Guide), I should be able to install VirtualBox silently like this
C:\temp> VirtualBox-6.1.28-147628-Win.exe --silent --ignore-reboot
and if I run the above command in a Windows command prompt, it succeeds and installs VirtualBox.
Now I do this in Ansible
- name: "Install {{ artifact_filename }}"
win_package:
path: "C:\\temp\\VirtualBox-6.1.28-147628-Win.exe"
arguments: "--silent --ignore-reboot"
state: present
and I get this when I run the playbook with the task.
fatal: [10.227.x.x]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"arguments": "--silent --ignore-reboot",
"chdir": null,
"client_cert": null,
"client_cert_password": null,
"creates_path": null,
"creates_service": null,
"creates_version": null,
"expected_return_code": [
0,
3010
],
"follow_redirects": "safe",
"force_basic_auth": false,
"headers": null,
"http_agent": "ansible-httpget",
"log_path": null,
"maximum_redirection": 50,
"password": null,
"path": "C:\\temp\\VirtualBox-6.1.28-147628-Win.exe",
"product_id": null,
"provider": "auto",
"proxy_password": null,
"proxy_url": null,
"proxy_use_default_credential": false,
"proxy_username": null,
"state": "present",
"url_method": null,
"url_password": null,
"url_timeout": 30,
"url_username": null,
"use_default_credential": false,
"use_proxy": true,
"username": null,
"validate_certs": true,
"wait_for_children": false
}
},
"msg": "unexpected rc from 'C:\\temp\\VirtualBox-6.1.28-147628-Win.exe --silent --ignore-reboot': see rc, stdout, and stderr for more details",
"rc": 1,
"reboot_required": false,
"stderr": "",
"stderr_lines": [],
"stdout": "",
"stdout_lines": []
}
What am I missing? TIA.
I RTFM'd the win_package documentation. It says regarding the arguments option
arguments This is only used for the msi, msp, and registry providers.
So I do this instead
- name: "Install VirtualBox"
win_command: "C:\\temp\\VirtualBox-6.1.28-147628-Win.exe --silent --ignore-reboot"
If anyone has a better answer I'm all eyes.

Unable to get product version. How to set CLASSPATH using ansible

I can get the weblogic version by doing this on the command prompt in unix.
$ . /app/wlserv*/server/bin/setWLSEnv.sh
$ java weblogic.version
I wish to grab the weblogic version using ansible on remote hosts so I wrote this playbook:
---
- hosts: dest_nodes
tasks:
- name: Get weblogic version
shell: "/app/wlserv*/server/bin/setWLSEnv.sh;java weblogic.version"
register: wlsversion
- debug:
msg: "{{ wlsversion }}"
However, I get this error:
fatal: [10.0.0.91]: FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"cmd": "/app/wlserv*/server/bin/setWLSEnv.sh;java weblogic.version",
"delta": "0:00:00.271434",
"end": "2020-05-15 16:31:44.209506",
"invocation": {
"module_args": {
"_raw_params": "/app/wlserv*/server/bin/setWLSEnv.sh;java weblogic.version",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"msg": "non-zero return code",
"rc": 1,
"start": "2020-05-15 16:31:43.938072",
"stderr": "Error: Could not find or load main class weblogic.version",
"stderr_lines": [
"Error: Could not find or load main class weblogic.version"
],
"stdout": "CLASSPATH=/usr/java/jdk1.8.0_192-amd64/lib/tools.jar:/app/wlserver/modules/features/wlst.wls.classpath.jar:\n\nPATH=/app/wlserver/server/bin:/app/wlserver/../oracle_common/modules/thirdparty/org.apache.ant/1.9.8.0.0/apache-ant-1.9.8/bin:/usr/java/jdk1.8.0_192-amd64/jre/bin:/usr/java/jdk1.8.0_192-amd64/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/app/wlserver/../oracle_common/modules/org.apache.maven_3.2.5/bin\n\nYour environment has been set.",
"stdout_lines": [
"CLASSPATH=/usr/java/jdk1.8.0_192-amd64/lib/tools.jar:/app/wlserver/modules/features/wlst.wls.classpath.jar:",
"",
"PATH=/app/wlserver/server/bin:/app/wlserver/../oracle_common/modules/thirdparty/org.apache.ant/1.9.8.0.0/apache-ant-1.9.8/bin:/usr/java/jdk1.8.0_192-amd64/jre/bin:/usr/java/jdk1.8.0_192-amd64/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/app/wlserver/../oracle_common/modules/org.apache.maven_3.2.5/bin",
"",
"Your environment has been set."
]
}
From the output, I see that the classpath did get set but java weblogic.version command failed on the remote host.
Can you please suggest how can i get the Weblogic version registered to wlsversion variable ?
Wow, I found the solution after some efforts. Posting the solution here. I'm sure many face this issue.
---
- hosts: dest_nodes
tasks:
- name: Get weblogic CLASSPATH
shell: "/app/wlserv*/server/bin/setWLSEnv.sh"
register: wlsenv
- name: Get weblogic Version
shell: "java weblogic.version"
environment:
CLASSPATH: "{{ wlsenv.stdout }}"
register: wlsversion
- debug:
msg: "{{ wlsversion }}"

Ansible parse debug output

I have this ansible output got from 3 different hosts, using ansible debug module:
TASK [debug] ***************************************************************************************************************************************************************************************
ok: [10.240.22.44] => {
"msg": {
"changed": true,
"msg": "All items completed",
"results": [
{
"_ansible_ignore_errors": true,
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/opt/confluent/bin/nodefirmware smm1",
"delta": "0:00:00.128325",
"end": "2020-02-05 11:22:19.435049",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/opt/confluent/bin/nodefirmware smm1",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "10.240.18.20",
"rc": 0,
"start": "2020-02-05 11:22:19.306724",
"stderr": "",
"stderr_lines": [],
"stdout": "smm1: SMM: 1.10 (TESM14F)\nsmm1: PSOC: 0.7",
"stdout_lines": [
"smm1: SMM: 1.10 (TESM14F)",
"smm1: PSOC: 0.7"
]
},
{
"_ansible_ignore_errors": true,
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/opt/confluent/bin/nodefirmware smm1",
"delta": "0:00:00.096292",
"end": "2020-02-05 11:22:22.847949",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/opt/confluent/bin/nodefirmware smm1",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "10.240.19.21",
"rc": 0,
"start": "2020-02-05 11:22:22.751657",
"stderr": "",
"stderr_lines": [],
"stdout": "smm1: SMM: 1.10 (TESM14F)\nsmm1: PSOC: 0.7",
"stdout_lines": [
"smm1: SMM: 1.10 (TESM14F)",
"smm1: PSOC: 0.7"
]
}
]
}
}
I'm trying to parse this output and display in the end, for each hosts, strictly the:
"stdout_lines": [
"smm1: SMM: 1.10 (TESM14F)",
"smm1: PSOC: 0.7"
The playbook that shows the above output is this:
- debug:
msg: "{{ smm_output }}"
when: "('primary' in default_hostname or 'Primary' in default_hostname)"
tags: ['ic', 'smm']
I tried with "{{ smm_output.stdout_lines }}" but says there's not such dict object
Any clues?
You are registering the output of a looping task. Quoting the documentation:
When you register a variable in a task with a loop, the registered variable contains a value for each item in the loop. The data structure placed in the variable during the loop will contain a results attribute, that is a list of all responses from the module. For a more in-depth example of how this works, see the Loops section on using register with a loop.
To debug each stdout_lines of your respective results in smm_output you can use the following task:
- name: debug result
debug:
var: item.stdout_lines
loop: "{{ smm_output.results }}"
Ref: https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#registering-variables

Ansible shell module does not recognize "failed" attribute on a failed task

Following code results 'dict object' has no attribute 'failed' error:
shell module:
- hosts: localhost
tasks:
- shell: "not_available_command"
register: module_result
until: module_result.failed == false
retries: 2
delay: 1
Result:
fatal: [localhost]: FAILED! => {
"failed": true,
"msg": "The conditional check 'module_result.failed == false' failed. The error was: error while evaluating conditional (module_result.failed == false): 'dict object' has no attribute 'failed'"
}
But when I changed the syntax of until as:
until: module_result.stderr == ""
It successfully retries. I executed it with -vvv option for debugging; after 2 retries it failed as expected:
fatal: [localhost]: FAILED! => {
"attempts": 2,
"changed": true,
"cmd": "not_available_command",
"delta": "0:00:00.010290",
"end": "2017-09-25 17:28:14.078318",
"failed": true,
"invocation": {
"module_args": {
"_raw_params": "not_available_command",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
}
},
"rc": 127,
"start": "2017-09-25 17:28:14.068028",
"stderr": "/bin/sh: 1: not_available_command: not found",
"stderr_lines": [
"/bin/sh: 1: not_available_command: not found"
],
"stdout": "",
"stdout_lines": []
}
As seen both failed or stderr attributes are existed however failed is not recognized when tried to define until syntax.
Let's try with a different module:
get_url module:
- hosts: localhost
tasks:
- get_url:
url: "http://unavailable_file_on_the_web.txt"
dest: "{{ playbook_dir }}"
register: module_result
until: module_result.failed == false
retries: 2
delay: 1
This time until: module_result.failed == false syntax works; 'failed' attribute is recognized.
So how to identify this issue on modules? Does it seem to be a bug?
Yes, it seems like a bug or not expected behaviour: failed field is not populated during intermediate attempts. You can inspect it with ANSIBLE_DEBUG=1:
{
"changed": true,
"end": "2017-09-25 13:01:17.269225",
"stdout": "",
"cmd": "not_available_command",
"rc": 127,
"start": "2017-09-25 13:01:17.257604",
"stderr": "/bin/sh: not_available_command: command not found",
"delta": "0:00:00.011621",
"invocation": {
"module_args": {
"warn": true,
"executable": null,
"_uses_shell": true,
"_raw_params": "not_available_command",
"removes": null,
"creates": null,
"chdir": null
}
},
"warnings": []
}
In Ansible 2.4 the failed field is present.
For your information there are task result tests like failed/succeeded.
You can use them in your when/until statements:
until: module_result | succeeded
This works well in 2.2.x and 2.3.x.

How to Store and display the output of shell command run in loop using with_lines

Below is the playbook i have created. I am not getting the way to store and display the output od the shell command and pass the same output to other play having different hosts.
---
- hosts: localhost
tasks:
- name: "check the connectivity with username for all the LLC servers from hosts.new file"
shell: ssh dp794d#{{ item }} "date"
register: result
with_lines: cat "/home/capio/ansible/pmossWipm/day2/logs/ipAddress.txt"
- debug: var=result
Now how can i display the result of register variable "result". I tried using the debug, but it didn't worked.
Below is the output of var=result
TASK [debug] *******************************************************************
ok: [localhost] => {
"result": {
"changed": true,
"msg": "All items completed",
"results": [
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "ssh dp794d#130.6.50.131 \"date\"",
"delta": "0:00:00.237866",
"end": "2017-05-09 08:59:13.918581",
"invocation": {
"module_args": {
"_raw_params": "ssh dp794d#130.6.50.131 \"date\"",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
},
"module_name": "command"
},
"item": "130.6.50.131",
"rc": 0,
"start": "2017-05-09 08:59:13.680715",
"stderr": " _________________________________________________________________\n\n This system is restricted to ABC authorized users for business\n purposes. Unauthorized access is a violation of the law. This\n service may be monitored for administrative and security reasons.\n By proceeding, you consent to this monitoring.\n _________________________________________________________________\n\n ,
"stdout": "Tue May 9 08:59:13 EDT 2017",
"stdout_lines": [
"Tue May 9 08:59:13 EDT 2017"
],
"warnings": []
},
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "ssh dp794d#130.6.50.132 \"date\"",
"delta": "0:00:00.245660",
"end": "2017-05-09 08:59:14.430728",
"invocation": {
"module_args": {
"_raw_params": "ssh dp794d#130.6.50.132 \"date\"",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
},
"module_name": "command"
},
"item": "130.6.50.132",
"rc": 0,
"start": "2017-05-09 08:59:14.185068",
"stderr": " _________________________________________________________________\n\n This system is restricted to ABC authorized users for business\n purposes. Unauthorized access is a violation of the law. This\n service may be monitored for administrative and security reasons.\n By proceeding, you consent to this monitoring.\n _________________________________________________________________\n\n [,
"stdout": "Tue May 9 08:59:14 EDT 2017",
"stdout_lines": [
"Tue May 9 08:59:14 EDT 2017"
],
"warnings": []
}
]
}
}
You can store result to file as follows:
- copy:
content: '{{ result.results | map(attribute="stdout") | list | join("\n") }}'
dest: /tmp/out.txt

Resources