Re: [ansible-project] with_items to get values from a shell cmd output

2020-04-09 Thread Kiran Kumar
@Dick Visser 

*Wow, that helped, thanks a lot ! *

*Thanks for the valuable suggestions & nice explanation as well *



On Thursday, April 9, 2020 at 12:31:02 AM UTC-7, Dick Visser wrote:
>
> The result from your grep/awk shell task consists of multiple lines, each 
> with one PID.
> So instead of stdout you should use stdout_lines: 
> https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#stdout-lines
>  
>
> Also, you are iterating over a list of 1 item, which is incorrect as well.
>
>
> Also, you're trying to establish something called "os_type" using a shell 
> task, but that is not necessary - this is already available in the ansible 
> facts (which you've explicitly gathered).
> So just use 'ansible_system' instead.
>
> Also, you declare "become: yes", but also "remote_user: root". That's 
> double. Either connect as non-root user and only declare "become: yes" 
> (which implies become_user = root). Or just only declare "remote_user: 
> root".
>
> Try this:
>
> - hosts: temp
>   gather_facts: yes
>   remote_user: root
>   tasks:
>- name: Adjust OOM to negative so that OOM killer does not kill below 
> processes
>  shell: 'ps -ef|egrep 
> "sssd|wdmd|portreserve|autofs|automount|ypbind|rpcbind|rpc.statd|rpc.mountd|rpc.idampd|ntpd|lmgrd|Xvnc|vncconfig|irqblance|rpc.rquotad|metric|nscd|crond|snpslmd|
> getpwname.pl|mysqld|rsyslogd|xinetd|sendmail|lsf|tigervnc|tightvnc|cfadm" 
> |egrep -ve "ps|egrep" |awk "{print \$2}"'
>  register: oom
>  when: ansible_system == 'Linux'
>- debug:  var=oom.stdout
>- name: update the pid 
>  raw: echo -17 > /proc/{{ item }}/oom_adj
>loop: "{{ oom.stdout_lines }}"
>
>
>
> On Thu, 9 Apr 2020 at 09:06, Kiran Kumar > 
> wrote:
>
>>
>> I got this error for below code - FAILED! => {"msg": "template error 
>> while templating string: expected token 'end of print statement', got '='. 
>> String: {{ var=oom.stdout }}"} 
>>
>> Please suggest , i am trying to get pid from shell cmd & then update it 
>> with echo 
>>
>> - hosts: temp
>>>   gather_facts: yes
>>>   become: yes
>>>   remote_user: root
>>>   tasks:
>>>- name: Capture uname ouput
>>>  shell: "uname"
>>>  register: os_type
>>>- name: Adjust OOM to negative so that OOM killer does not kill below 
>>> processes
>>>  shell: 'ps -ef|egrep 
>>> "sssd|wdmd|portreserve|autofs|automount|ypbind|rpcbind|rpc.statd|rpc.mountd|rpc.idampd|ntpd|lmgrd|Xvnc|vncconfig|irqblance|rpc.rquotad|metric|nscd|crond|snpslmd|
>>> getpwname.pl|mysqld|rsyslogd|xinetd|sendmail|lsf|tigervnc|tightvnc|cfadm" 
>>> |egrep -ve "ps|egrep" |awk "{print \$2}"'
>>>  register: oom
>>>  when: os_type.stdout == 'Linux'
>>>- debug:  var=oom.stdout
>>>- name: update the pid 
>>>  raw: echo -17 > /proc/{{ item.pid }}/oom_adj
>>> with_items:
>>>- "{{ var=oom.stdout }}"
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/620d6682-3345-4069-a31d-78d53924c3aa%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> Dick Visser
> Trust & Identity Service Operations Manager
> GÉANT
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/89e1a3e3-28aa-4793-919b-fdfdf24767a1%40googlegroups.com.


Re: [ansible-project] with_items to get values from a shell cmd output

2020-04-09 Thread Stefan Hornburg (Racke)
On 4/9/20 9:30 AM, Dick Visser wrote:
> The result from your grep/awk shell task consists of multiple lines, each 
> with one PID.
> So instead of stdout you should use
> stdout_lines: 
> https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#stdout-lines
>  
> 
> Also, you are iterating over a list of 1 item, which is incorrect as well.
> 
> 
> Also, you're trying to establish something called "os_type" using a shell 
> task, but that is not necessary - this is
> already available in the ansible facts (which you've explicitly gathered).
> So just use 'ansible_system' instead.
> 
> Also, you declare "become: yes", but also "remote_user: root". That's double. 
> Either connect as non-root user and only
> declare "become: yes" (which implies become_user = root). Or just only 
> declare "remote_user: root".
> 
> Try this:
> 
> - hosts: temp
>   gather_facts: yes
>   remote_user: root
>   tasks:
>    - name: Adjust OOM to negative so that OOM killer does not kill below 
> processes
>      shell: 'ps -ef|egrep
> "sssd|wdmd|portreserve|autofs|automount|ypbind|rpcbind|rpc.statd|rpc.mountd|rpc.idampd|ntpd|lmgrd|Xvnc|vncconfig|irqblance|rpc.rquotad|metric|nscd|crond|snpslmd|getpwname.pl
> |mysqld|rsyslogd|xinetd|sendmail|lsf|tigervnc|tightvnc|cfadm"
>  |egrep -ve "ps|egrep" |awk "{print \$2}"'
>      register: oom
>      when: ansible_system == 'Linux'
>    - debug:  var=oom.stdout
>    - name: update the pid
>      raw: echo -17 > /proc/{{ item }}/oom_adj
>        loop: "{{ oom.stdout_lines }}"
> 

This looks like a bad hack to me. Why don't you adjust OOMScoreAdjust in the 
system unit files of these services (or
corresponding setting in init scripts) ??

Regards
 Racke

> 
> 
> On Thu, 9 Apr 2020 at 09:06, Kiran Kumar  > wrote:
> 
> 
> I got this error for below code - FAILED! => {"msg": "template error 
> while templating string: expected token 'end of
> print statement', got '='. String: {{ var=oom.stdout }}"} 
> 
> Please suggest , i am trying to get pid from shell cmd & then update it 
> with echo 
> 
> - hosts: temp
>   gather_facts: yes
>   become: yes
>   remote_user: root
>   tasks:
>    - name: Capture uname ouput
>      shell: "uname"
>      register: os_type
>    - name: Adjust OOM to negative so that OOM killer does not kill 
> below processes
>      shell: 'ps -ef|egrep
> 
> "sssd|wdmd|portreserve|autofs|automount|ypbind|rpcbind|rpc.statd|rpc.mountd|rpc.idampd|ntpd|lmgrd|Xvnc|vncconfig|irqblance|rpc.rquotad|metric|nscd|crond|snpslmd|getpwname.pl
> 
> |mysqld|rsyslogd|xinetd|sendmail|lsf|tigervnc|tightvnc|cfadm"
>  |egrep -ve "ps|egrep" |awk
> "{print \$2}"'
>      register: oom
>      when: os_type.stdout == 'Linux'
>    - debug:  var=oom.stdout
>    - name: update the pid 
>      raw: echo -17 > /proc/{{ item.pid }}/oom_adj
> with_items:
>    - "{{ var=oom.stdout }}"
> 
> -- 
> 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 view this discussion on the web visit
> 
> https://groups.google.com/d/msgid/ansible-project/620d6682-3345-4069-a31d-78d53924c3aa%40googlegroups.com
> 
> .
> 
> 
> 
> -- 
> Dick Visser
> Trust & Identity Service Operations Manager
> GÉANT
> 
> -- 
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAL8fbwOVV-SB4aHQZ%2BHWAixVnJKNQQoxJCTqxQXuDZmcUTW7Hw%40mail.gmail.com
> .


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d66a3052-6a2b-6930-87c1-5c105c998ea2%40linuxia.de.


signature.asc
Description: 

Re: [ansible-project] with_items to get values from a shell cmd output

2020-04-09 Thread Dick Visser
The result from your grep/awk shell task consists of multiple lines, each
with one PID.
So instead of stdout you should use stdout_lines:
https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#stdout-lines


Also, you are iterating over a list of 1 item, which is incorrect as well.


Also, you're trying to establish something called "os_type" using a shell
task, but that is not necessary - this is already available in the ansible
facts (which you've explicitly gathered).
So just use 'ansible_system' instead.

Also, you declare "become: yes", but also "remote_user: root". That's
double. Either connect as non-root user and only declare "become: yes"
(which implies become_user = root). Or just only declare "remote_user:
root".

Try this:

- hosts: temp
  gather_facts: yes
  remote_user: root
  tasks:
   - name: Adjust OOM to negative so that OOM killer does not kill below
processes
 shell: 'ps -ef|egrep
"sssd|wdmd|portreserve|autofs|automount|ypbind|rpcbind|rpc.statd|rpc.mountd|rpc.idampd|ntpd|lmgrd|Xvnc|vncconfig|irqblance|rpc.rquotad|metric|nscd|crond|snpslmd|
getpwname.pl|mysqld|rsyslogd|xinetd|sendmail|lsf|tigervnc|tightvnc|cfadm"
|egrep -ve "ps|egrep" |awk "{print \$2}"'
 register: oom
 when: ansible_system == 'Linux'
   - debug:  var=oom.stdout
   - name: update the pid
 raw: echo -17 > /proc/{{ item }}/oom_adj
   loop: "{{ oom.stdout_lines }}"



On Thu, 9 Apr 2020 at 09:06, Kiran Kumar  wrote:

>
> I got this error for below code - FAILED! => {"msg": "template error while
> templating string: expected token 'end of print statement', got '='.
> String: {{ var=oom.stdout }}"}
>
> Please suggest , i am trying to get pid from shell cmd & then update it
> with echo
>
> - hosts: temp
>>   gather_facts: yes
>>   become: yes
>>   remote_user: root
>>   tasks:
>>- name: Capture uname ouput
>>  shell: "uname"
>>  register: os_type
>>- name: Adjust OOM to negative so that OOM killer does not kill below
>> processes
>>  shell: 'ps -ef|egrep
>> "sssd|wdmd|portreserve|autofs|automount|ypbind|rpcbind|rpc.statd|rpc.mountd|rpc.idampd|ntpd|lmgrd|Xvnc|vncconfig|irqblance|rpc.rquotad|metric|nscd|crond|snpslmd|
>> getpwname.pl|mysqld|rsyslogd|xinetd|sendmail|lsf|tigervnc|tightvnc|cfadm"
>> |egrep -ve "ps|egrep" |awk "{print \$2}"'
>>  register: oom
>>  when: os_type.stdout == 'Linux'
>>- debug:  var=oom.stdout
>>- name: update the pid
>>  raw: echo -17 > /proc/{{ item.pid }}/oom_adj
>> with_items:
>>- "{{ var=oom.stdout }}"
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/620d6682-3345-4069-a31d-78d53924c3aa%40googlegroups.com
> 
> .
>


-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwOVV-SB4aHQZ%2BHWAixVnJKNQQoxJCTqxQXuDZmcUTW7Hw%40mail.gmail.com.


[ansible-project] with_items to get values from a shell cmd output

2020-04-09 Thread Kiran Kumar

I got this error for below code - FAILED! => {"msg": "template error while 
templating string: expected token 'end of print statement', got '='. 
String: {{ var=oom.stdout }}"} 

Please suggest , i am trying to get pid from shell cmd & then update it 
with echo 

- hosts: temp
>   gather_facts: yes
>   become: yes
>   remote_user: root
>   tasks:
>- name: Capture uname ouput
>  shell: "uname"
>  register: os_type
>- name: Adjust OOM to negative so that OOM killer does not kill below 
> processes
>  shell: 'ps -ef|egrep 
> "sssd|wdmd|portreserve|autofs|automount|ypbind|rpcbind|rpc.statd|rpc.mountd|rpc.idampd|ntpd|lmgrd|Xvnc|vncconfig|irqblance|rpc.rquotad|metric|nscd|crond|snpslmd|getpwname.pl|mysqld|rsyslogd|xinetd|sendmail|lsf|tigervnc|tightvnc|cfadm"
>  
> |egrep -ve "ps|egrep" |awk "{print \$2}"'
>  register: oom
>  when: os_type.stdout == 'Linux'
>- debug:  var=oom.stdout
>- name: update the pid 
>  raw: echo -17 > /proc/{{ item.pid }}/oom_adj
> with_items:
>- "{{ var=oom.stdout }}"

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/620d6682-3345-4069-a31d-78d53924c3aa%40googlegroups.com.