Ansible playbook with become_method=pbrun not working - ansible

I am a beginner on Ansible. I am trying to run command as a db user and we have pbrun setup for changing users in my company.
Below is how my pbrun policy is defined as :
[ RunAs User ] [ Command ]
root /bin/su - couchbase
root /bin/su - enterprisedb
From ansible.cfg (only sharing privilege_escalation part):
[privilege_escalation]
become=true
become_method=pbrun
become_user=''
become_ask_pass=False
become_flags: '/bin/su - enterprisedb'
From playbook :
$ cat ping.yml
- name: Test
hosts: all
gather_facts: false
any_errors_fatal: false
tasks:
- shell: whoami
register: output
- debug:
msg: "{{output.stdout}}"
Below is how I am running playbook.
ansible-playbook -i sample.host1.list ping.yml -k -vvvv
Output :
$ ansible-playbook -i sample.host1.list ping.yml -k -vvvv
ansible-playbook 2.8.12
config file = /home/ads_username/ansible_work_dir/ansible.cfg
configured module search path = [u'/adshome/ads_username/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Sep 26 2019, 13:23:47) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /home/ads_username/ansible_work_dir/ansible.cfg as config file
SSH password:
setting up inventory plugins
host_list declined parsing /home/ads_username/ansible_work_dir/sample.host1.list as it did not pass it's verify_file() method
auto declined parsing /home/ads_username/ansible_work_dir/sample.host1.list as it did not pass it's verify_file() method
yaml declined parsing /home/ads_username/ansible_work_dir/sample.host1.list as it did not pass it's verify_file() method
Parsed /home/ads_username/ansible_work_dir/sample.host1.list inventory source with ini plugin
Loading callback plugin debug of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/debug.pyc
Loading callback plugin profile_tasks of type aggregate, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/profile_tasks.pyc
PLAYBOOK: ping.yml ******************************************************************************************************************************************
Positional arguments: ping.yml
ask_pass: True
become_method: pbrun
inventory: (u'/home/ads_username/ansible_work_dir/sample.host1.list',)
forks: 5
tags: (u'all',)
verbosity: 4
connection: paramiko
timeout: 10
become: True
1 plays in ping.yml
PLAY [Adding VM to inventory] *******************************************************************************************************************************
META: ran handlers
TASK [shell] ************************************************************************************************************************************************
task path: /home/ads_username/ansible_work_dir/ping.yml:6
Wednesday 10 November 2021 15:21:32 -0700 (0:00:00.053) 0:00:00.053 ****
<server_name.region.company.com> ESTABLISH PARAMIKO SSH CONNECTION FOR USER: None on PORT 22 TO server_name.region.company.com
<server_name.region.company.com> EXEC /bin/bash -c '( umask 77 && mkdir -p "` echo /tmp `"&& mkdir /tmp/ansible-tmp-1636582892.39-15614-57850062632655 && echo ansible-tmp-1636582892.39-15614-57850062632655="` echo /tmp/ansible-tmp-1636582892.39-15614-57850062632655 `" ) && sleep 0'
<server_name.region.company.com> Attempting python interpreter discovery
<server_name.region.company.com> EXEC /bin/bash -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'python2.6'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
<server_name.region.company.com> Python interpreter discovery fallback (pipelining support required for extended interpreter discovery)
Using module file /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py
<server_name.region.company.com> PUT /adshome/ads_username/.ansible/tmp/ansible-local-155953Afqz2/tmpgNQgMu TO /tmp/ansible-tmp-1636582892.39-15614-57850062632655/AnsiballZ_command.py
<server_name.region.company.com> EXEC /bin/bash -c 'chmod u+x /tmp/ansible-tmp-1636582892.39-15614-57850062632655/ /tmp/ansible-tmp-1636582892.39-15614-57850062632655/AnsiballZ_command.py && sleep 0'
<server_name.region.company.com> EXEC /bin/bash -c 'echo BECOME-SUCCESS-sgemmsfapenzvcsbxdnbjneynirmhzkl; echo "/usr/bin/python /tmp/ansible-tmp-1636582892.39-15614-57850062632655/AnsiballZ_command.py"|pbrun /bin/su - enterprisedb && sleep 0'
<server_name.region.company.com> EXEC /bin/bash -c 'rm -f -r /tmp/ansible-tmp-1636582892.39-15614-57850062632655/ > /dev/null 2>&1 && sleep 0'
[WARNING]: Platform linux on host server_name.region.company.com is using the discovered Python interpreter at /usr/bin/python, but future installation of
another Python interpreter could change this. See https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html for more information.
fatal: [server_name.region.company.com]: FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"rc": 2
}
MSG:
MODULE FAILURE
See stdout/stderr for the exact error
MODULE_STDOUT:
Last login: Wed Nov 10 15:21:02 MST 2021
/usr/bin/python: can't open file '/tmp/ansible-tmp-1636582892.39-15614-57850062632655/AnsiballZ_command.py': [Errno 13] Permission denied
PLAY RECAP **************************************************************************************************************************************************
server_name.region.company.com : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Wednesday 10 November 2021 15:21:35 -0700 (0:00:03.141) 0:00:03.194 ****
===============================================================================
shell ------------------------------------------------------------------------------------------------------------------------------------------------ 3.14s
/home/ads_username/ansible_work_dir/ping.yml:6 --------------------------------------------------------------------------------------------------------------------
Please help guide me on what is wrong in my setup and if it is possible to make this work without changing anything in my pbrun policy.

Related

UNREACHABLE! => ***"changed": false, "msg": "[Errno -3] Try again" | Github runner

Am trying to use Ansible via Google IAP tunnel to update my VM's. I have followed the below repo
https://github.com/joeheaton/ansible-gcp
I get the below error. while running the playbook:
TASK [Gathering Facts] *********************************************************
fatal: [10.170.0.25]: UNREACHABLE! => ***"changed": false, "msg": "[Errno -3] Try again", "unreachable": true***
PLAY RECAP *********************************************************************
10.170.0.25 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
Below is my workflow file:
name: 'Ansible Config STG'
on:
workflow_dispatch:
inputs:
logLevel:
description: environment
required: true
default: stg
jobs:
playbook-dev:
name: 'Ansible Install'
runs-on: ubuntu-latest
environment: stg
container: gcr.io/google.com/cloudsdktool/cloud-sdk:286.0.0-alpine
env:
ANSIBLE_HOST_KEY_CHECKING: "False"
ANSIBLE_BECOME: "True"
OS_LOGIN_SSH_TTL: "1h"
ANSIBLE_REMOTE_USER: to-be-calculated-during-job
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Config file
run: |
ls -al
- name: Set up Ansible & SSH
run: |
apk add ansible --update
echo $STG_PRIVATE_KEY > account.json
gcloud auth activate-service-account --key-file=account.json --project=test-staging
pip3 install requests google-auth
apk add jq --update
mkdir ~/.ssh
echo $FTP_SERVER_KEY_STG > ~/.ssh/id_rsa
ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa <<< y
chmod 600 ~/.ssh/id_rsa
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
gcloud compute os-login ssh-keys add --key-file ~/.ssh/id_rsa.pub --ttl $OS_LOGIN_SSH_TTL
export ANSIBLE_REMOTE_USER="sa_$(cat account.json | jq -r '.client_id')"
export ANSIBLE_HOST_KEY_CHECKING=False
export GOOGLE_APPLICATION_CREDENTIALS="account.json"
ansible-playbook -v -i inventory.gcp.yaml test.playbook.yml
env:
STG_PRIVATE_KEY: ${{ secrets.GOOGLE_PRIVATE_KEY_TF_STG }}
FTP_SERVER_KEY: ${{ secrets.FTP_SERVER_KEY_STG }}
Any suggestions or help would be really appreciated.

starting jboss server using ansible and returning back control [duplicate]

This question already has answers here:
Ansible Command module says that '|' is illegal character
(2 answers)
Closed 5 years ago.
Below yaml playbook restarts the jboss server but doesnt get back control to execute next ansible command. I have also used wait for module to stop waiting for current command result and go for next command. But still ansbile hangs on current command indefinitely . Please let me know when I went wrong?
---
- hosts: test1
tasks:
- name: simple command
become: true
command: whoami
register: output
- debug:
msg: "I gave the command whoami and the out is '{{output.stdout}}'"
- name: change to jboss user
become: true
become_user: jboss
command: whoami
register: output
- debug:
msg: "I gave the command whoami and the out is '{{output.stdout}}'"
- name: start jboss server as jboss user
become: true
become_user: jboss
command: sh /usr/jboss/bin/run.sh -c XXXXXXXX -b x.x.x.x &
when: inventory_hostname in groups['test1']
register: restartscript
- debug:
msg: "output of server restart command is '{{restartscript.stdout}}'"
- name: waiting for server to come back
local_action:
module: wait_for
timeout=20
host=x.x.x.x
port=8080
delay=6
state=started
terminal output message
ESTABLISH SSH CONNECTION FOR USER: XXXXXXXXXXX
SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=XXXXXXXXX -o ConnectTimeout=10 -o ControlPath=/home/tcprod/XXXXXXXXXX/.ansible/cp/ansible-ssh-%h-%p-%r -tt X.X.X.X '/bin/sh -c '"'"'sudo -H -S -p "[sudo via ansible, key=hvgwnsbxpkxvbcmtcfvvsplfphdrevxg] password: " -u jboss /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-hvgwnsbxpkxvbcmtcfvvsplfphdrevxg; /usr/bin/python /tmp/ansible-tmp-XXXXXXXXX.XX-XXXXXXXXXXXXXX/command.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''
The & is not allowed in Ansible "command".
command: sh /usr/jboss/bin/run.sh -c XXXXXXXX -b x.x.x.x &
Try removing it or use shell instead of command.
From Ansible documentation about command:
The given command [...] will not
be processed through the shell, so variables like $HOME and operations
like "<", ">", "|", ";" and "&" will not work (use the shell module if
you need these features).

Ansible lineinfile give an error with /etc/hosts

I have this simple task in my role:
- name: Updating the /etc/hosts
lineinfile: dest=/etc/hosts line="192.168.99.100 {{ item }}"
with_items:
- domain1.com
- domain2.com
tags: etc
When I run my Ansible playbook:
robe:ansible-develop robe$ ansible-playbook -i inventory develop-env.yml -vvvv --extra-vars "user=`whoami`" --tags etc --become-user=robe --ask-become-pass
SUDO password:
PLAY [127.0.0.1] **************************************************************
GATHERING FACTS ***************************************************************
<127.0.0.1> REMOTE_MODULE setup
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p /tmp/ansible-tmp-1446050161.27-256837595805154 && chmod a+rx /tmp/ansible-tmp-1446050161.27-256837595805154 && echo /tmp/ansible-tmp-1446050161.27-256837595805154']
<127.0.0.1> PUT /var/folders/x1/dyrdksh50tj0z2szv3zx_9rc0000gq/T/tmpMYjnXz TO /tmp/ansible-tmp-1446050161.27-256837595805154/setup
<127.0.0.1> EXEC ['/bin/sh', '-c', 'chmod a+r /tmp/ansible-tmp-1446050161.27-256837595805154/setup']
<127.0.0.1> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=rqphpqfpcbsifqtnwflmmlmpwrcnkpqe] password: " -u robe /bin/sh -c '"'"'echo BECOME-SUCCESS-rqphpqfpcbsifqtnwflmmlmpwrcnkpqe; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /tmp/ansible-tmp-1446050161.27-256837595805154/setup'"'"''
<127.0.0.1> EXEC ['/bin/sh', '-c', 'rm -rf /tmp/ansible-tmp-1446050161.27-256837595805154/ >/dev/null 2>&1']
ok: [127.0.0.1]
TASK: [docker-tool-box | Updating the /etc/hosts] *****************************
<127.0.0.1> REMOTE_MODULE lineinfile dest=/etc/hosts line="192.168.99.100 ptxrt.com"
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p /tmp/ansible-tmp-1446050161.49-9492873099893 && chmod a+rx /tmp/ansible-tmp-1446050161.49-9492873099893 && echo /tmp/ansible-tmp-1446050161.49-9492873099893']
<127.0.0.1> PUT /var/folders/x1/dyrdksh50tj0z2szv3zx_9rc0000gq/T/tmpyLOGd6 TO /tmp/ansible-tmp-1446050161.49-9492873099893/lineinfile
<127.0.0.1> EXEC ['/bin/sh', '-c', u'chmod a+r /tmp/ansible-tmp-1446050161.49-9492873099893/lineinfile']
<127.0.0.1> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=nofwziqxytbhjwhluhtzdfcqclqjuypv] password: " -u robe /bin/sh -c '"'"'echo BECOME-SUCCESS-nofwziqxytbhjwhluhtzdfcqclqjuypv; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /tmp/ansible-tmp-1446050161.49-9492873099893/lineinfile'"'"''
<127.0.0.1> EXEC ['/bin/sh', '-c', 'rm -rf /tmp/ansible-tmp-1446050161.49-9492873099893/ >/dev/null 2>&1']
failed: [127.0.0.1] => (item=ptxrt.com) => {"failed": true, "item": "ptxrt.com"}
msg: The destination directory (/private/etc) is not writable by the current user.
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit #/Users/robe/develop-env.retry
127.0.0.1 : ok=1 changed=0 unreachable=0 failed=1
I don't understand why the error msg said:
msg: The destination directory (/private/etc) is not writable by the current user.
The correct directory should be /etc/hosts.
Any clue?
I am working on MacOS.
My playbook is:
- hosts: 127.0.0.1
connection: local
become: yes
become_method: sudo
become_user: "{{user}}"
roles:
- role-1
- role-2
I put the become_user by command line. So all my roles are running with become. And it still doesn't work.
On OSX the /etc/ folder is actually a symlink to the /private/etc/ folder - hence the error. (Ansible is just transparently following the symlink).
As for the error you're going to need to run the task with become: yes (sudo permissions) to be able to write to /etc/hosts/
Edit based on update and commments
To get the correct privileges to edit the hosts file you need to be root. Setting become: yes on the task is good enough for this for OSX as Ansible will default to sudo as the become method and root as the user.
To specify the sudo password you can do one of two things.
Use --ask-become-pass on the command line and Ansible will prompt you when it needs it
Use the ansible_become_pass variable on the group or host in the inventory file. E.g. localhost ansible_become_pass=batman
Note that the Ansible docs recommend against 2 and using 1 so as not to store your password in plain text.

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

Ansible 1.9.2/latest.
OS: CentOS 6.7/later
JAVA_HOME, PATH variable and all other things are setup correctly.
I have the following playbook runs in my perf_tests/tasks/main.yml. To just run this playbook run only, I'm using Ansible tags.
# Run JMeter tests
- name: Run JMeter test(s)
# command: "export PATH={{ jdk_install_dir }}/bin:$PATH && export JAVA_HOME={{ jdk_install_dir }} && {{ jmeter_install_dir }}/bin/jmeter -n -t {{ common_download_dir}}/perf_tests/ProjectTest1.jmx -l {{ common_download_dir}}/perf_tests/log_jmeter_ProjectTest1.jtl"
command: export PATH={{ jdk_install_dir }}/bin:$PATH && export JAVA_HOME={{ jdk_install_dir }} && /apps/jmeter/apache-jmeter-2.13/bin/jmeter -n -t /tmp/perf_tests/ProjectTest1.jmx -l /tmp/perf_tests/log_jmeter_ProjectTest1.jtl
become_user: "{{ common_user }}"
tags:
- giga
Files required by JMeter executable are present on the target machine and I'm using "command" module in ansible to start JMeter.
[appuser#jmeter01 ~]$ ls -l /apps/jmeter/apache-jmeter-2.13/bin/jmeter /tmp/perf_tests/ProjectTest1.jmx
-rwxr-xr-x. 1 appuser appgroup 5589 Mar 8 2015 /apps/jmeter/apache-jmeter-2.13/bin/jmeter
-rw-r--r--. 1 appuser appgroup 50194 Oct 2 12:19 /tmp/perf_tests/ProjectTest1.jmx
[appuser#jmeter01 ~]$
[appuser#jmeter01 ~]$ which java
/apps/jdk/jdk1.7.0_67/bin/java
When I'm running the above playbook run jmeter on a .jmx file to generate a a result .jtl file (using ANSIBLE), it's errors out with an error code 2 (as shown below): msg: [Errno 2] No such file or directory
ANSIBLE output:
TASK: [perf_tests | Run JMeter test(s)] ***************************************
<jmeter01.perf.jenkins> ESTABLISH CONNECTION FOR USER: confman on PORT 22 TO jmeter01.perf.jenkins
<jmeter01.perf.jenkins> REMOTE_MODULE command export PATH=/apps/jdk/jdk1.7.0_67/bin:$PATH && export JAVA_HOME=/apps/jdk/jdk1.7.0_67 && /apps/jmeter/apache-jmeter-2.13/bin/jmeter -n -t /tmp/perf_tests/ProjectTest1.jmx -l /tmp/perf_tests/log_jmeter_ProjectTest1.jtl
<jmeter01.perf.jenkins> EXEC /bin/sh -c 'mkdir -p /tmp/ansible-tmp-1443821195.89-232957509929426 && chmod a+rx /tmp/ansible-tmp-1443821195.89-232957509929426 && echo /tmp/ansible-tmp-1443821195.89-232957509929426'
<jmeter01.perf.jenkins> PUT /tmp/tmp6fAr1W TO /tmp/ansible-tmp-1443821195.89-232957509929426/command
<jmeter01.perf.jenkins> EXEC /bin/sh -c 'chmod a+r /tmp/ansible-tmp-1443821195.89-232957509929426/command'
<jmeter01.perf.jenkins> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=pkivlaidiolrcxvyxxixeysvrfkpvroy] password: " -u appuser /bin/sh -c '"'"'echo BECOME-SUCCESS-pkivlaidiolrcxvyxxixeysvrfkpvroy; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /tmp/ansible-tmp-1443821195.89-232957509929426/command'"'"''
<jmeter01.perf.jenkins> EXEC /bin/sh -c 'rm -rf /tmp/ansible-tmp-1443821195.89-232957509929426/ >/dev/null 2>&1'
failed: [jmeter01.perf.jenkins] => {"cmd": "export PATH=/apps/jdk/jdk1.7.0_67/bin:/sbin:/bin:/usr/sbin:/usr/bin '&&' export JAVA_HOME=/apps/jdk/jdk1.7.0_67 '&&' /apps/jmeter/apache-jmeter-2.13/bin/jmeter -n -t /tmp/perf_tests/ProjectTest1.jmx -l /tmp/perf_tests/log_jmeter_ProjectTest1.jtl", "failed": true, "rc": 2}
msg: [Errno 2] No such file or directory
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
The "cmd" above in ansible's -vvvv verbose output shows, everything is getting passed/expanded successfully by Ansible for calling the jmeter command but it's failing.
IF I go to the remote machine (jmeter01) and "appuser" and run the command, it works fine and successfully creates the -l option provided .jtl result file.
[appuser#jmeter01 ~]$ /apps/jmeter/apache-jmeter-2.13/bin/jmeter -n -t /tmp/perf_tests/ProjectTest1.jmx -l /tmp/perf_tests/log_jmeter_ProjectTest1.jtl
Creating summariser <summary>
Created the tree successfully using /tmp/perf_tests/ProjectTest1.jmx
Starting the test # Fri Oct 02 17:23:50 EDT 2015 (1443821030343)
Waiting for possible shutdown message on port 4445
summary = 240 in 4.4s = 54.0/s Avg: 82 Min: 2 Max: 1113 Err: 0 (0.00%)
Tidying up ... # Fri Oct 02 17:23:55 EDT 2015 (1443821035009)
... end of run
[appuser#jmeter01 ~]$ ls -l /tmp/perf_tests
total 80
-rw-r--r--. 1 appuser appgroup 50194 Oct 2 12:19 ProjectTest1.jmx
-rw-r--r--. 1 appuser appgroup 22412 Oct 2 17:23 log_jmeter_ProjectTest1.jtl
drwxr-xr-x. 3 appuser appgroup 4096 Oct 2 12:19 META-INF
[appuser#jmeter01 ~]$
I'm stumped why JMeter is erroring out with this error while running it with Ansible!!! ?
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.
Compare the outputs of:
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'"
and you can see this clearly.
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 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).
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.
# 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' }
run_jmeter_test.sh looks like (very plain / simple version):
#!/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.

Unable to run top on a remote host via Ansible

I have the following playbook:
---
- hosts: ESNodes
remote_user: ihazan
tasks:
- name: Run Monitoring
action: command /tmp/monitoring/cpu_mon
The content of /tmp/monitoring/cpu_mon is as follows:
top -bn1800 -p $(ps -ef | grep elasticsearch | grep -v grep | grep -v sudo | awk '{print $2}') | grep root > /tmp/cpu_stats &
Pay attention that top is run the the background with &
When running that playbook Ansible get stuck forever on the top command:
-bash-4.1$ ansible-playbook es_playbook_run.yml -l PerfSetup -K -f 10
sudo password:
PLAY [ESNodes] ****************************************************************
GATHERING FACTS ***************************************************************
ok: [isk-vsrv643]
TASK: [Run Monitoring] ********************************************************
When running it via remote SSH(which is what ansible should do) it works fine:
-bash-4.1$ ssh ihazan#isk-vsrv643 'nohup /tmp/monitoring/cpu_mon'
-bash-4.1$
Following is the debug version of the output:
-bash-4.1$ ansible-playbook es_playbook_run.yml -l PerfSetup -K -f 10 -vvvv
sudo password:
PLAY [ESNodes] ****************************************************************
GATHERING FACTS ***************************************************************
<isk-vsrv643> ESTABLISH CONNECTION FOR USER: ihazan on PORT 22 TO isk-vsrv643
<isk-vsrv643> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-1393860499.75-256362698809430 && chmod a+rx $HOME/.ansible/tmp/ansible-1393860499.75-256362698809430 && echo $HOME/.ansible/tmp/ansible-1393860499.75-256362698809430'
<isk-vsrv643> REMOTE_MODULE setup
<isk-vsrv643> PUT /tmp/tmpZh9bYP TO /usr2/ihazan/.ansible/tmp/ansible-1393860499.75-256362698809430/setup
<isk-vsrv643> EXEC /bin/sh -c '/usr/bin/python /usr2/ihazan/.ansible/tmp/ansible-1393860499.75-256362698809430/setup; rm -rf /usr2/ihazan/.ansible/tmp/ansible-1393860499.75-256362698809430/ >/dev/null 2>&1'
ok: [isk-vsrv643]
TASK: [Run Monitoring] ********************************************************
<isk-vsrv643> ESTABLISH CONNECTION FOR USER: ihazan on PORT 22 TO isk-vsrv643
<isk-vsrv643> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-1393860500.32-92141081389545 && chmod a+rx $HOME/.ansible/tmp/ansible-1393860500.32-92141081389545 && echo $HOME/.ansible/tmp/ansible-1393860500.32-92141081389545'
<isk-vsrv643> REMOTE_MODULE command /tmp/monitoring/cpu_mon
<isk-vsrv643> PUT /tmp/tmp7dYRPY TO /usr2/ihazan/.ansible/tmp/ansible-1393860500.32-92141081389545/command
<isk-vsrv643> EXEC /bin/sh -c '/usr/bin/python /usr2/ihazan/.ansible/tmp/ansible-1393860500.32-92141081389545/command; rm -rf /usr2/ihazan/.ansible/tmp/ansible-1393860500.32-92141081389545/ >/dev/null 2>&1'
Thx in advance
Use fire and forget mode, i.e. async + poll 0 :
---
- hosts: ESNodes
remote_user: ihazan
tasks:
- name: Run Monitoring
action: command /tmp/monitoring/cpu_mon
async: 45
poll: 0
Whole scoop on async is here : http://docs.ansible.com/playbooks_async.html
Good luck.

Resources