Re: [ansible-project] Command not working on remote host through shell module or playbook

2016-10-09 Thread Kai Stian Olstad

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

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f4dcd5f3-2395-4a04-138c-da9bf99fe68c%40olstad.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Command not working on remote host through shell module or playbook

2016-09-22 Thread bablu

  Can some one help here. 



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)}'
>
> Not working
>
> /usr/bin/ansible test -m raw -a netstat -an | grep :8080
>
>
>
> On Wednesday, September 21, 2016 at 1:21:29 PM UTC+5:30, Kai Stian Olstad 
> wrote:
>>
>> On 20.09.2016 10:00, DHAVAL JAISWAL wrote: 
>> > Ansible version: ansible 1.9.2 
>> > 
>> > I am unable to execute following command from shell module neither 
>> > through 
>> > playbook. It could be any command at the run time. While reading found 
>> > $,% 
>> > need the escape string. Tried but not working. Is there any way/module 
>> > through which i can run any command on the remote host and no need to 
>> > explicitly define any escape string. 
>> > 
>> > 
>> > netstat -tanpu | awk '{{print $5}}' | sort -n | uniq -cd | sort -n | 
>> > awk 
>> > '$1 > 3{{printf ("%5s\t%s\n", $1, $2)}}' 
>> > 
>> > With shell module: 
>> > 
>> > /usr/bin/ansible remote_host -m shell -a 'netstat -tanpu | awk '{{print 
>> > $5}}' | sort -n | uniq -cd | sort -n | awk '$1 > 3{{printf 
>> > ("%5s\t%s\n", 
>> > $1, $2)}}'' 
>> > -bash: syntax error near unexpected token `(' 
>> > 
>> > 
>> > With playbook. 
>> > 
>> > - hosts: "{{ip}}" 
>> >   gather_facts: no 
>> >   remote_user: remote 
>> >   connection: local 
>> > 
>> >   tasks: 
>> >- name: Running command 
>> >  shell: netstat -tanpu | awk '{{print $5}}' | sort -n | uniq -cd | 
>> > sort 
>> > -n | awk '$1 > 3{{printf ("%5s\t%s\n", $1, $2)}}' 
>> > 
>> > fatal: [192.168.4.7] => Failed to template netstat -tanpu | awk 
>> > '{{print 
>> > $5}}' | sort -n | uniq -cd | sort -n | awk '$1 > 3{{printf 
>> > ("%5s\t%s\n", 
>> > $1, $2)}}': template error while templating string: unexpected char 
>> > u'$' at 
>> > 30 
>>
>> Ansible thinks {{ }} is a template, you need to just use { }, so this 
>> should work: 
>>
>> - name: Running command 
>>shell: netstat -tanpu | awk '{print $5}' | sort -n | uniq -cd | sort 
>> -n | awk '$1 > 3{printf ("%5s\t%s\n",$1, $2)}' 
>>
>> -- 
>> Kai Stian Olstad 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3a5e2b12-f260-41cd-97fe-fd1df672b068%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Command not working on remote host through shell module or playbook

2016-09-21 Thread bablu

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)}'

Not working

/usr/bin/ansible test -m raw -a netstat -an | grep :8080



On Wednesday, September 21, 2016 at 1:21:29 PM UTC+5:30, Kai Stian Olstad 
wrote:
>
> On 20.09.2016 10:00, DHAVAL JAISWAL wrote: 
> > Ansible version: ansible 1.9.2 
> > 
> > I am unable to execute following command from shell module neither 
> > through 
> > playbook. It could be any command at the run time. While reading found 
> > $,% 
> > need the escape string. Tried but not working. Is there any way/module 
> > through which i can run any command on the remote host and no need to 
> > explicitly define any escape string. 
> > 
> > 
> > netstat -tanpu | awk '{{print $5}}' | sort -n | uniq -cd | sort -n | 
> > awk 
> > '$1 > 3{{printf ("%5s\t%s\n", $1, $2)}}' 
> > 
> > With shell module: 
> > 
> > /usr/bin/ansible remote_host -m shell -a 'netstat -tanpu | awk '{{print 
> > $5}}' | sort -n | uniq -cd | sort -n | awk '$1 > 3{{printf 
> > ("%5s\t%s\n", 
> > $1, $2)}}'' 
> > -bash: syntax error near unexpected token `(' 
> > 
> > 
> > With playbook. 
> > 
> > - hosts: "{{ip}}" 
> >   gather_facts: no 
> >   remote_user: remote 
> >   connection: local 
> > 
> >   tasks: 
> >- name: Running command 
> >  shell: netstat -tanpu | awk '{{print $5}}' | sort -n | uniq -cd | 
> > sort 
> > -n | awk '$1 > 3{{printf ("%5s\t%s\n", $1, $2)}}' 
> > 
> > fatal: [192.168.4.7] => Failed to template netstat -tanpu | awk 
> > '{{print 
> > $5}}' | sort -n | uniq -cd | sort -n | awk '$1 > 3{{printf 
> > ("%5s\t%s\n", 
> > $1, $2)}}': template error while templating string: unexpected char 
> > u'$' at 
> > 30 
>
> Ansible thinks {{ }} is a template, you need to just use { }, so this 
> should work: 
>
> - name: Running command 
>shell: netstat -tanpu | awk '{print $5}' | sort -n | uniq -cd | sort 
> -n | awk '$1 > 3{printf ("%5s\t%s\n",$1, $2)}' 
>
> -- 
> Kai Stian Olstad 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f5a06c26-f449-40e5-ab82-85dec4e81d17%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Command not working on remote host through shell module or playbook

2016-09-21 Thread Kai Stian Olstad

On 20.09.2016 10:00, DHAVAL JAISWAL wrote:

Ansible version: ansible 1.9.2

I am unable to execute following command from shell module neither 
through
playbook. It could be any command at the run time. While reading found 
$,%

need the escape string. Tried but not working. Is there any way/module
through which i can run any command on the remote host and no need to
explicitly define any escape string.


netstat -tanpu | awk '{{print $5}}' | sort -n | uniq -cd | sort -n | 
awk

'$1 > 3{{printf ("%5s\t%s\n", $1, $2)}}'

With shell module:

/usr/bin/ansible remote_host -m shell -a 'netstat -tanpu | awk '{{print
$5}}' | sort -n | uniq -cd | sort -n | awk '$1 > 3{{printf 
("%5s\t%s\n",

$1, $2)}}''
-bash: syntax error near unexpected token `('


With playbook.

- hosts: "{{ip}}"
  gather_facts: no
  remote_user: remote
  connection: local

  tasks:
   - name: Running command
 shell: netstat -tanpu | awk '{{print $5}}' | sort -n | uniq -cd | 
sort

-n | awk '$1 > 3{{printf ("%5s\t%s\n", $1, $2)}}'

fatal: [192.168.4.7] => Failed to template netstat -tanpu | awk 
'{{print
$5}}' | sort -n | uniq -cd | sort -n | awk '$1 > 3{{printf 
("%5s\t%s\n",
$1, $2)}}': template error while templating string: unexpected char 
u'$' at

30


Ansible thinks {{ }} is a template, you need to just use { }, so this 
should work:


- name: Running command
  shell: netstat -tanpu | awk '{print $5}' | sort -n | uniq -cd | sort 
-n | awk '$1 > 3{printf ("%5s\t%s\n",$1, $2)}'


--
Kai Stian Olstad

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/88272a328beede70e0bf0829f62def65%40olstad.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Command not working on remote host through shell module or playbook

2016-09-20 Thread DHAVAL JAISWAL
Ansible version: ansible 1.9.2

I am unable to execute following command from shell module neither through
playbook. It could be any command at the run time. While reading found $,%
need the escape string. Tried but not working. Is there any way/module
through which i can run any command on the remote host and no need to
explicitly define any escape string.


netstat -tanpu | awk '{{print $5}}' | sort -n | uniq -cd | sort -n | awk
'$1 > 3{{printf ("%5s\t%s\n", $1, $2)}}'

With shell module:

/usr/bin/ansible remote_host -m shell -a 'netstat -tanpu | awk '{{print
$5}}' | sort -n | uniq -cd | sort -n | awk '$1 > 3{{printf ("%5s\t%s\n",
$1, $2)}}''
-bash: syntax error near unexpected token `('


With playbook.

- hosts: "{{ip}}"
  gather_facts: no
  remote_user: remote
  connection: local

  tasks:
   - name: Running command
 shell: netstat -tanpu | awk '{{print $5}}' | sort -n | uniq -cd | sort
-n | awk '$1 > 3{{printf ("%5s\t%s\n", $1, $2)}}'

fatal: [192.168.4.7] => Failed to template netstat -tanpu | awk '{{print
$5}}' | sort -n | uniq -cd | sort -n | awk '$1 > 3{{printf ("%5s\t%s\n",
$1, $2)}}': template error while templating string: unexpected char u'$' at
30

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAH5ShBiDOStckyhbZNihw4HyC2-VcTp364y2SfhgTzgBmcSPDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.