On 22. sep. 2016 16:47, bablu wrote:
> Can some one help here.
You have multiple challenges to overcome, so what you are trying to
achieve is going to be rather difficult.
> On Wednesday, September 21, 2016 at 10:14:16 PM UTC+5:30, bablu wrote:
>>
>>
>> That's working.
>>
>> But I guess here i have to hard code the command. Is there any way where i
>> can pass any command at the run time to execute on the remote host.
>>
>> I saw the raw module and below are the behavior i got.
>>
>> working:
>>
>> /usr/bin/ansible test -m raw -a netstat -tanpu | /bin/awk '{print $5}' |
>> sort -n | uniq -cd | sort -n | awk '$1 > 3{printf ("%5s\t%s\n", $1, $2)}'
This is not working as you expect. Since you are not quoting the -a.
It's actually running
/usr/bin/ansible test -m raw -a netstat -tanpu
Only "netstat" is running on the host test. -t is a valid option to
ansible, and it is saving the result in directory anpu. If you check
your directory where you run ansible from you will see this directory.
The rest of the command
| /bin/awk '{print $5}' | sort -n | uniq -cd | sort -n | awk '$1 >
3{printf ("%5s\t%s\n", $1, $2)}'
is running on the control machine and not the remote host.
>> Not working
>>
>> /usr/bin/ansible test -m raw -a netstat -an | grep :8080
This is not working since you don't have quotes, ansible doesn't support
using -a twice.
I short, because of your shell expansion and Ansible expansion, this is
not trivial to get right. You will need to use alternating single and
double quotes and escaping things to prevent expansions.
You might wont to look at ansible-console, then you don't have to think
about shell expansion.
Or explain why you need to do this, maybe someone here can show a better
way to solve you need.
--
Kai Stian Olstad