# Using variable to compare stdout parameter

**URL:** <https://forum.ansible.com/t/using-variable-to-compare-stdout-parameter/33024>\
**Category:** Ansible Project\
**Created:** [May 26, 2020, 3:11am UTC](https://forum.ansible.com/t/using-variable-to-compare-stdout-parameter/33024 "2020-05-26T03:11:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sivakumar\_Saravanamu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@Sivakumar\_Saravanamu](https://forum.ansible.com/u/Sivakumar_Saravanamu)\
**Post date:** [May 26, 2020, 3:11am UTC](https://forum.ansible.com/t/using-variable-to-compare-stdout-parameter/33024/1 "2020-05-26T03:11:28Z")

</div>

Hi

I am writing a post build verification task and servers are located in three difference location.

US, EU and AU

I want to check chrony.conf output so that if servers in group\_names US it should check chrony.conf file to see server parameter is reflect NTP server in that region and so on. How do I achieve this goal.

In /var/main.yml I have following server list

ntp\_server1: “IP address based on location”  
ntp\_server2: “IP address based on location”  
ntp\_server3: “IP address based on location”  
ntp\_server4: “IP address based on location”  
ntp\_server5: “IP address based on location”  
ntp\_server6: “IP address based on location”

in task/main.yml

I have following task

- name: read the chrony file  
shell: grep ‘server’ /etc/chrony.conf  
register: source\_one

> From here I don’t know how to proceed further to check how ntp\_server1 to ntp\_server6 based on location.

I have jinja2 template in template directory

{% if ‘US’ in group\_names %}  
server {{ ntp\_server1 }}  
server {{ ntp\_server2 }}  
{% elif ‘AU’ in group\_names %}  
server {{ ntp\_server3 }}  
server {{ ntp\_server4 }}  
{% else %}  
server {{ ntp\_server5 }}  
server {{ ntp\_server6 }}  
{% endif %}

Not sure how to integrate with the verification task. Please help me how to achieve verification outcome based on location.

Regards,  
Siva

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 26, 2020, 6:50am UTC](https://forum.ansible.com/t/using-variable-to-compare-stdout-parameter/33024/2 "2020-05-26T06:50:36Z")

</div>

I don’t understand what you are trying to achieve?

You are trying to find out a server’s region based on its configured ntp servers? But you already have inventory groups for each location.

Can you describe your REAL goal, and include that mysterious build verification task as well. And the inventory.

---

<div class="post-metadata">

**Author:** ![Sivakumar\_Saravanamu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@Sivakumar\_Saravanamu](https://forum.ansible.com/u/Sivakumar_Saravanamu)\
**Post date:** [May 26, 2020, 7:15am UTC](https://forum.ansible.com/t/using-variable-to-compare-stdout-parameter/33024/3 "2020-05-26T07:15:06Z")

</div>

OK here it is.

I have build a server X expecting all the parameter are in place.

During validation and qualification phase the user who didn’t build that server has to cross check parameter using simple playbook to make sure server has right chrony server IP address and other basic setting are in place, if not validation has to fail and send notification to the server builder to rectify the same.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 26, 2020, 7:18am UTC](https://forum.ansible.com/t/using-variable-to-compare-stdout-parameter/33024/4 "2020-05-26T07:18:25Z")

</div>

> OK here it is.
> 
> I have build a server X expecting all the parameter are in place.
> 
> During validation and qualification phase the user who didn't build that server has to cross check parameter using  
> simple playbook to make sure server has right chrony server IP address and other basic setting are in place, if not  
> validation has to fail and send notification to the server builder to rectify the same.

Why wouldn't you verify the server before turning it over to the user?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Sivakumar\_Saravanamu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@Sivakumar\_Saravanamu](https://forum.ansible.com/u/Sivakumar_Saravanamu)\
**Post date:** [May 26, 2020, 7:28am UTC](https://forum.ansible.com/t/using-variable-to-compare-stdout-parameter/33024/5 "2020-05-26T07:28:35Z")

</div>

Sometimes you are not in position to ask question 🙂 that is my position now. Boss want this validation playbook and I not getting clue regarding how to verify chrony parameters of three different location in single playbook.

I used Jinja2 template to deploy those ntp server configuration one sysadmin didn’t use it properly and it created lot of noise now management want validation playbook. This is the story for my requirement.

Now someone call help me on this requirement 🙂

---

<div class="post-metadata">

**Author:** ![Sivakumar\_Saravanamu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@Sivakumar\_Saravanamu](https://forum.ansible.com/u/Sivakumar_Saravanamu)\
**Post date:** [May 27, 2020, 11:46am UTC](https://forum.ansible.com/t/using-variable-to-compare-stdout-parameter/33024/6 "2020-05-27T11:46:33Z")

</div>

I sorted out

- name: read the chrony file  
shell: grep ‘server’ /etc/chrony.conf  
register: source\_one

- name: Checking the NTP Source  
when:

- source\_one.stdout is search(“_\>_\>_\>_”) and source\_one.stdout is search(" _\>_\>_\>_ ")

- “‘AUS’ in group\_names”  
debug:  
msg: “source\_one is present in Australia”
