# Checking for a string and value

**URL:** <https://forum.ansible.com/t/checking-for-a-string-and-value/26953>\
**Category:** Ansible Project\
**Created:** [March 10, 2018, 5:38am UTC](https://forum.ansible.com/t/checking-for-a-string-and-value/26953 "2018-03-10T05:38:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vino\_B](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@Vino\_B](https://forum.ansible.com/u/Vino_B)\
**Post date:** [March 10, 2018, 5:38am UTC](https://forum.ansible.com/t/checking-for-a-string-and-value/26953/1 "2018-03-10T05:38:13Z")

</div>

Hi All,

Request your help, I need to find whether the string numa\_balancing is set to disabled in the file /etc/default/grub where the string in contained in the string GRUB\_CMDLINE\_LINUX\_DEFAULT any help on this is much appreciated.

cat /etc/default/grub|grep GRUB\_CMDLINE\_LINUX\_DEFAULT  
GRUB\_CMDLINE\_LINUX\_DEFAULT=“root=/dev/hda1 disk=/dev/hda resume=swap console=ttyS0,115200n8 multipath=off net.ifnames=0 NON\_PERSISTENT\_DEVICE\_NAMES=1 quiet elevator=noop intel\_idle.max\_cstate=1 processor.max\_cstate=1 numa\_balancing=disable”

From,  
Vino.B

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 10, 2018, 7:06pm UTC](https://forum.ansible.com/t/checking-for-a-string-and-value/26953/2 "2018-03-10T19:06:53Z")

</div>

There are many ways to do that, here is one

&nbsp;&nbsp;- slurp:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: /etc/default/grub  
&nbsp;&nbsp;&nbsp;&nbsp;register: r

&nbsp;&nbsp;- debug: msg="Found it"  
&nbsp;&nbsp;&nbsp;&nbsp;when: r.content | b64decode | regex\_search('^GRUB\_CMDLINE\_LINUX\_DEFAULT=.\*numa\_balancing=disable')

---

<div class="post-metadata">

**Author:** ![Vino\_B](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@Vino\_B](https://forum.ansible.com/u/Vino_B)\
**Post date:** [March 11, 2018, 6:45am UTC](https://forum.ansible.com/t/checking-for-a-string-and-value/26953/3 "2018-03-11T06:45:48Z")

</div>

Hi Kai,

Thank you very much, but the above solution always states tune eve when the search criteria is changed eg. in the above code if you change the =disable" to =“disbaleX” it should fail, but the output states as successful

when: r.content | b64decode | regex\_search(‘^GRUB\_CMDLINE\_LINUX\_DEFAULT=.\*numa\_balancing=disableX’)

From,  
Vino.B

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 11, 2018, 9:20am UTC](https://forum.ansible.com/t/checking-for-a-string-and-value/26953/4 "2018-03-11T09:20:45Z")

</div>

I made a little test and can't confirm this

$ cat grub  
GRUB\_CMDLINE\_LINUX\_DEFAULT="root=/dev/hda1 disk=/dev/hda resume=swap console=ttyS0,115200n8 multipath=off net.ifnames=0 NON\_PERSISTENT\_DEVICE\_NAMES=1 quiet elevator=noop intel\_idle.max\_cstate=1 processor.max\_cstate=1 numa\_balancing=disable"

cat test.yml

---

<div class="post-metadata">

**Author:** ![Vino\_B](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@Vino\_B](https://forum.ansible.com/u/Vino_B)\
**Post date:** [March 11, 2018, 12:17pm UTC](https://forum.ansible.com/t/checking-for-a-string-and-value/26953/5 "2018-03-11T12:17:02Z")

</div>

Hi Kai,

Below is the playbook does not execute the debug part , can you help me what is wrong in the below play book.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 11, 2018, 12:47pm UTC](https://forum.ansible.com/t/checking-for-a-string-and-value/26953/6 "2018-03-11T12:47:58Z")

</div>

> &nbsp;&nbsp;Below is the playbook does not execute the debug part , can you help me  
> what is wrong in the below play book.
> 
> ---  
> - hosts: target  
> &nbsp;&nbsp;remote\_user: ansible  
> &nbsp;&nbsp;become: true  
> &nbsp;&nbsp;become\_method: sudo  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;- slurp:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: /etc/default/grub  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: r  
> &nbsp;&nbsp;&nbsp;- name: Check whether AutoNuma is disabled  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug: msg="Found it"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when:  
> r.content|b64decode|regex\_search('^GRUB\_CMDLINE\_LINUX\_DEFAULT=.\*numa\_balancing=disableX')
> 
> OUTPUT:

\<snip /\>

> TASK [Check whether AutoNuma is disabled]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> skipping: [10.162.54.34]

The file does not have disableX in it so it will not run the task.  
If you are looking for the opposite behaviour you need to add "not"

when: not (r.content|b64decode|regex\_search('^GRUB\_CMDLINE\_LINUX\_DEFAULT=.\*numa\_balancing=disableX'))

---

<div class="post-metadata">

**Author:** ![Vino\_B](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@Vino\_B](https://forum.ansible.com/u/Vino_B)\
**Post date:** [March 12, 2018, 6:31am UTC](https://forum.ansible.com/t/checking-for-a-string-and-value/26953/7 "2018-03-12T06:31:11Z")

</div>

Hi Kai,

Thank you very much
