Rectangle 27 0

performance testing ansible command module: JMeter msg: [Errno 2] No such file or directory?


ansible myserver -m command -a "echo Hello && echo Goodbye"
ansible myserver -m command -a "export GREET=Hello && echo '$GREET'"

ansible myserver -m shell -a "echo Hello && echo Goodbye"
ansible myserver -m shell -a "export GREET=Hello && echo '$GREET'"

@ArunSangal Using export and && only looked like it fixed the JMeter not detecting Java error. That error was caused by JMeter running and not finding Java, because the environment variable wasn't set. When you added the "export JAVA_HOME..." stuff, the command actually failed earlier. It stopped complaining about Java because it never even got as far as running JMeter. It failed immediately on "export" because that wasn't a command it could run (because it was a builtin). Hope this explains it better!

@ArunSangal but you're correct that in your case, it was the "export" rather than the && that was throwing the error first. I've updated my answer to expand on this.

First you were trying to run the command ".../jmeter <stuff>" and it wouldn't work because the java environment variables weren't set up. Then you tried to run "export PATH=<stuff> &&..." and that gave "no such file or directory" because there's no such program as "export": it's a shell builtin. And also && wouldn't work anyway.

Strange, one thing is sure that using export and && solved the issue for JMeter not detecting java executable (my first error which I didn't past) and also after using export and &&, the command module didn't error out. I saw in the docs as you mentioned that it doesn't expand shell expansion, >, <, |, & etc and you are correct there.

Yes, shell worked. I'll share the solution but the fact that && didn't work, that's wrong. I used it to set JAVA_HOME n PATH variables and ansible command module didn't error out and found "java" executable for running "jmeter" executable. Earlier when I was not using command: "export JAVA_HOME={{ jdk_install_dir }} && export PATH={{ jdk_install_dir }}/bin:$PATH && ....whole...jmeter with params" command.. Jmeter executable was failing to find java but after using && it worked but the error was No such file or directory (for jmx file i guess or not sure)

You can't use export or && with the command module as it executes the command directly, not through a shell, and export is a shell builtin.

You want the shell module.

and you can see this clearly.

Note
Rectangle 27 0

performance testing ansible command module: JMeter msg: [Errno 2] No such file or directory?


# Run JMeter tests using Ansible shell module on remote Jmeter node
- name: Run JMeter tests using Ansible shell module on remote Jmeter node and pass parameters
  shell: "sudo {{ common_download_dir }}/perf_tests/run_jmeter_test.sh {{ jdk_install_dir }} {{ jmeter_install_dir }}/bin/jmeter {{ common_download_dir }}/perf_tests/{{ item.jmxfile }}.jmx {{ common_download_dir }}/perf_tests/log_jmeter_{{ item.jmxfile }}.jtl"
  become_user: "{{ common_user }}"
  with_items:
    - { jmxfile: 'ProjectTest1' }
#    - { jmxfile: 'ProjectTest101' }
#    - { jmxfile: 'ProjectTest102' }

# Fetch JMeter test(s) result .jtl file(s) from remote server and put it in local workspace.
- name: Fetch JMeter test(s) result .jtl file(s)
  fetch: src="{{ common_download_dir}}/perf_tests/log_jmeter_{{ item.jmxfile }}.jtl" dest="perf_tests/{{ item.jmxfile}}.jtl" flat=yes fail_on_missing=yes
  with_items:
    - { jmxfile: 'ProjectTest1' }
#    - { jmxfile: 'ProjectTest101' }
#    - { jmxfile: 'ProjectTest102' }
#!/bin/sh

javaHome=$1
jmExec=$2
jmxFile=$3
jtlFile=$4

export PATH=$javaHome/bin:$PATH

$jmExec -n -t $jmxFile -l $jtlFile

Other posts by me also shows how I got JMeter executable and it's Extra/Standard/WebDriver plugins.

Seumasmac is correct. I couldn't find anywhere "command" module able to run jmeter to run the tests (I even tried hardcoding the values and passed it to command: xxx xxx xxx).

Using "with_items", I can pass jmxfile values and get multiple jmeter runs. Script: run_jmeter_test.sh is bundled in a ZIP file which I'm pushing first (using copy module) to the target/remote jmeter01 server in {{ common_download_dir }} == /tmp and I'm able to create perf_tests folder and unpack the ZIP there to get everything setup before running the playbook to run JMeter executable/command.

Using the following "shell" module I was able to run multiple .jmx (if a project has) and also fetch (get the result .jtl file back to Source server which was running ansible).

Note