Using variable to compare stdout parameter

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

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.

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.

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

Sometimes you are not in position to ask question :slight_smile: 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 :slight_smile:

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”