Hi Todd,

Thanks for assisting me on it, I did configure the playbook on my test 
machines and here is the output:

root@ansible-master /]# ansible-playbook hostname1.yml

PLAY [all] 
******************************************************************************************************************************

TASK [Gathering Facts] 
******************************************************************************************************************
ok: [ansible-client]
ok: [ansible-client1]

TASK [show file contents] 
***************************************************************************************************************
ok: [ansible-client] => {
    "msg": "Linux ansible-client 4.18.0-348.el8.x86_64\nLinux 
ansible-client1 4.18.0-348.el8.x86_64"
}
ok: [ansible-client1] => {
    "msg": "Linux ansible-client 4.18.0-348.el8.x86_64\nLinux 
ansible-client1 4.18.0-348.el8.x86_64"
}

TASK [Correct kernel?] 
******************************************************************************************************************
ok: [ansible-client]
ok: [ansible-client1]

TASK [Report via Debug] 
*****************************************************************************************************************
ok: [ansible-client] => {
    "msg": "Kernel_expectations_missed:\n\nKernel_expectations_matched:\n- 
ansible-client\n- ansible-client1\n\nKernel_expectations_error:\n\n"
}

PLAY RECAP 
******************************************************************************************************************************
ansible-client             : ok=4    changed=0    unreachable=0    failed=0 
   skipped=0    rescued=0    ignored=0
ansible-client1            : ok=3    changed=0    unreachable=0    failed=0 
   skipped=0    rescued=0    ignored=0

[root@ansible-master /]#

On Friday, December 31, 2021 at 10:56:42 AM UTC+5:30 Marian Saldhana wrote:

> Thanks Todd, appreciate your guidance.
>
> On Thursday, December 30, 2021 at 8:59:08 PM UTC+5:30 [email protected] 
> wrote:
>
>> Assuming “hostname” means a fully qualified domain name, then the 
>> following may help you.
>>
>> ---- hosts: all
>>   gather_facts: True
>>   become: false
>>   tasks:
>>   - name: show file contents
>>     debug:
>>       msg: "{{ lookup('file', 'customer-expects.txt') }}"
>>
>>   - name: Correct kernel?
>>     set_fact:
>>       # These dashes matter.
>>       expectation: |-
>>         {%- if lookup('file', 'customer-expects.txt')
>>               is regex([ansible_system,ansible_fqdn,ansible_kernel]|join(' 
>> ')|regex_escape()) -%}
>>         matched
>>         {%- else -%}
>>         missed
>>         {%- endif -%}
>>   - name: Report via Debug
>>     run_once: True
>>     debug:
>>       msg: |
>>         {% for exp in ['missed', 'matched', 'error'] %}
>>         Kernel_expectations_{{ exp }}:
>>         {%   for hosti in ansible_play_hosts_all|sort %}
>>         {%     if hostvars[hosti]['expectation']|d('error') == exp %}
>>         - {{ hosti }}
>>         {%     endif %}
>>         {%   endfor %}
>>         {% endfor %}
>>
>> This produces the following output given the command
>>
>> ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook customer-expects.yml 
>> --limit flakey.sample.net,shaggy.sample.net,scooby.sample.net,
>> clyde.sample.net -v
>>
>> Using /home/utoddl/.ansible.cfg as config file
>>
>> PLAY [all] ******************************
>>
>> TASK [Gathering Facts] ****************
>> fatal: [flakey.sample.net]: UNREACHABLE! => changed=false 
>>   msg: 'Failed to connect to the host via ssh: [email protected]: 
>> Permission denied (publickey,gssapi-keyex,gssapi-with-mic).'
>>   unreachable: true
>> ok: [scooby.sample.net]
>> ok: [shaggy.sample.net]
>> ok: [clyde.sample.net]
>>
>> TASK [show file contents] **************
>> ok: [clyde.sample.net] => 
>>   msg: |-
>>     Linux flakey.sample.net 5.15.11-200.fc35.x86_64
>>     Linux clyde.sample.net 5.15.11-200.fc35.x86_64
>>     Linux shaggy.sample.net 5.15.11-200.fc35.x86_64
>>     Linux scooby.sample.net 5.15.11-200.fc35.x86_64
>>     Linux loaner.sample.net 5.15.11-200.fc35.x86_64
>>
>> TASK [Correct kernel?] *****************
>> ok: [clyde.sample.net] => changed=false 
>>   ansible_facts:
>>     expectation: matched
>> ok: [shaggy.sample.net] => changed=false 
>>   ansible_facts:
>>     expectation: missed
>> ok: [scooby.sample.net] => changed=false 
>>   ansible_facts:
>>     expectation: matched
>>
>> TASK [Report via Debug] **************
>> ok: [clyde.sample.net] => 
>>   msg: |-
>>     Kernel_expectations_missed:
>>     - shaggy.sample.net
>>   
>>     Kernel_expectations_matched:
>>     - clyde.sample.net
>>     - scooby.sample.net
>>   
>>     Kernel_expectations_error:
>>     - flakey.sample.net
>>
>> PLAY RECAP ***************************clyde.sample.net     : ok=4    
>> changed=0    unreachable=0    failed=0    skipped=0    rescued=0    
>> ignored=0   shaggy.sample.net    : ok=2    changed=0    unreachable=0    
>> failed=0    skipped=0    rescued=0    ignored=0   flakey.sample.net    : 
>> ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    
>> ignored=0   scooby.sample.net    : ok=2    changed=0    unreachable=0    
>> failed=0    skipped=0    rescued=0    ignored=0   
>>
>> On 12/29/21 9:46 PM, Marian Saldhana wrote:
>>
>> Thanks for your reply. 
>>
>> *Expected value is: -  Linux hostname 4.18.0-193.el8.x86_64 ( The 
>> customer has RHEL 8.2 running in its env )*
>> I have 100 such lines given to me by the customer ( OS inventory ) where 
>> 80% of the values that I receive by running the ansible standard module 
>> matches with the expected value given by the customer. I need to understand 
>> how these values can be matched with the values given by the customer.
>>
>>
>>
>>
>> On Wednesday, December 29, 2021 at 10:56:06 PM UTC+5:30 [email protected] 
>> wrote:
>>
>>> What, exactly, do the "values given by the customer" look like? It 
>>> almost certainly isn't going to match the output of `uname -a`. (I'm 
>>> guessing. But please, don't make us guess; give us the details of the 
>>> actual problem.)
>>>
>>> On Monday, December 27, 2021 at 11:58:39 PM UTC-5 [email protected] 
>>> wrote:
>>>
>>>> Hi All, 
>>>>
>>>> This is my code:
>>>>
>>>> ---
>>>> # tasks file for uname
>>>>
>>>>       - name: Kernel version number
>>>>         register: uname_a
>>>>         command: "uname -a"
>>>>
>>>>       - debug:
>>>>           var: uname_a.stdout_lines
>>>>
>>>> +++
>>>>
>>>> TASK [uname_tab1 : debug] 
>>>> ***************************************************************************************************************
>>>> ok: [192.168.43.237] => {
>>>>     "uname_a.stdout_lines": [
>>>>         "Linux ansible-client 4.18.0-348.el8.x86_64 #1 SMP Tue Oct 19 
>>>> 15:14:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux"
>>>>     ]
>>>> }
>>>> ok: [192.168.43.6] => {
>>>>     "uname_a.stdout_lines": [
>>>>         "Linux ansible-client1 4.18.0-348.el8.x86_64 #1 SMP Tue Oct 19 
>>>> 15:14:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux"
>>>>     ]
>>>> }
>>>>
>>>> ++++
>>>>
>>>> Now I need to compare these values with the values given by the 
>>>> customer ( Linux ansible-client1 4.18.0-348.el8.x86_64 ) hence request 
>>>> your 
>>>> assistance out  here to write a program.
>>>> On Wednesday, December 22, 2021 at 5:36:21 AM UTC+5:30 [email protected] 
>>>> wrote:
>>>>
>>>>> That kind of info can be obtained with "gather facts" step, which is 
>>>>> the first step when running a playbook. 
>>>>>
>>>>> You just have to comparte returned info in ansible variables like 
>>>>> "ansible_distribution" and "ansible_distribution_version" with the 
>>>>> expected 
>>>>> value. You can store expected value in a local dictionary that uses 
>>>>> hostname as the key value.
>>>>>
>>>>> El martes, 21 de diciembre de 2021 a la(s) 08:15:15 UTC-3, 
>>>>> [email protected] escribió:
>>>>>
>>>>>> Thanks for your reply. 
>>>>>>
>>>>>> I want to automate tasks such as verifying the OS version of remote 
>>>>>> nodes.
>>>>>>
>>>>>> The customer has given me the expected value i.e. Centos version 8.2
>>>>>>
>>>>>> Through automation I wish to get the OS version of the remotes nodes 
>>>>>> and then compare that value with the value that I have received from the 
>>>>>> customer through ansible playbooks.
>>>>>> On Tuesday, December 21, 2021 at 4:06:57 PM UTC+5:30 
>>>>>> [email protected] wrote:
>>>>>>
>>>>>>> You need to elaborate some more, I can't make anything of your 
>>>>>>> story. 
>>>>>>> Give some real world examples of the tasks that you're trying to 
>>>>>>> automate. 
>>>>>>>
>>>>>>> On Tue, 21 Dec 2021 at 07:22, Marian Saldhana <[email protected]> 
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi All, 
>>>>>>>>
>>>>>>>> As I am new to ansible i need to write a role which compares input 
>>>>>>>> /output value.
>>>>>>>>
>>>>>>>> Let me elaborate.
>>>>>>>>
>>>>>>>> I need to write a role where I already have expected value, for eg 
>>>>>>>> hostname of ansible remote node - abc.
>>>>>>>>
>>>>>>>> Now I need to write a role which first will fetch the value from 
>>>>>>>> the remote node and then compare the fetched value with the expected 
>>>>>>>> value 
>>>>>>>> ( abc ) I have with me.
>>>>>>>>
>>>>>>>> Thanks.
>>>>>>>>
>>>>>>>>
>>>>>>>> -- 
>>>>>>>> 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 [email protected].
>>>>>>>> To view this discussion on the web visit 
>>>>>>>> https://groups.google.com/d/msgid/ansible-project/b708d4e2-ded7-44f0-b68a-866e93ec860bn%40googlegroups.com
>>>>>>>>  
>>>>>>>> <https://groups.google.com/d/msgid/ansible-project/b708d4e2-ded7-44f0-b68a-866e93ec860bn%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 [email protected].
>>
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/3f4e20ff-2ece-4441-ae03-d70a5802ca2cn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/3f4e20ff-2ece-4441-ae03-d70a5802ca2cn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> ​
>>
>> -- 
>> Todd
>>
>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/adb2c833-a67f-4a15-82a3-de15e285377en%40googlegroups.com.

Reply via email to