Using variable to compare stdout parameter

15 views
Skip to first unread message

Sivakumar Saravanamuthu

unread,
May 25, 2020, 11:11:28 PM5/25/20
to Ansible Project
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 
nameread the chrony file
  shellgrep 'server' /etc/chrony.conf
  registersource_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

Dick Visser

unread,
May 26, 2020, 2:51:08 AM5/26/20
to ansible...@googlegroups.com
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.

--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/197c96b3-51bf-43cd-b529-8015e3943814%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Sivakumar Saravanamuthu

unread,
May 26, 2020, 3:16:06 AM5/26/20
to ansible...@googlegroups.com
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. 




Thank you.
Regards,
Siva


Stefan Hornburg (Racke)

unread,
May 26, 2020, 3:18:55 AM5/26/20
to ansible...@googlegroups.com
On 5/26/20 9:15 AM, Sivakumar Saravanamuthu wrote:
> 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
Racke

>
>
> Thank you.
> Regards,
> Siva
>
>
> On Tue, 26 May 2020 at 16:50, Dick Visser <dick....@geant.org <mailto:dick....@geant.org>> wrote:
>
> 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.
>
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> <https://groups.google.com/d/msgid/ansible-project/197c96b3-51bf-43cd-b529-8015e3943814%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> Sent from a mobile device - please excuse the brevity, spelling and punctuation.
>
> --
> 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-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAL8fbwM968YYytDW5bAo6bbB%2BTNtJvx3_A03UfmRQKPdpiEypw%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAL8fbwM968YYytDW5bAo6bbB%2BTNtJvx3_A03UfmRQKPdpiEypw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> 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-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CANnu9FFVBcpDdUMWB%3D6oPcrE4OO95Z7SthH%2BNp%2BVYuB_Cr-1zA%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CANnu9FFVBcpDdUMWB%3D6oPcrE4OO95Z7SthH%2BNp%2BVYuB_Cr-1zA%40mail.gmail.com?utm_medium=email&utm_source=footer>.


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

signature.asc

Sivakumar Saravanamuthu

unread,
May 26, 2020, 3:29:26 AM5/26/20
to ansible...@googlegroups.com
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 :-)
Thank you.
Regards,
Siva


To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7643d4b9-34bc-3420-d514-c1c42117cfe3%40linuxia.de.

Sivakumar Saravanamuthu

unread,
May 27, 2020, 7:47:27 AM5/27/20
to ansible...@googlegroups.com
 I sorted out

nameread the chrony file
    shellgrep 'server' /etc/chrony.conf
    registersource_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"


Thank you.
Regards,
Siva

Reply all
Reply to author
Forward
0 new messages