# ansible module to read log file

**URL:** <https://forum.ansible.com/t/ansible-module-to-read-log-file/35576>\
**Category:** Ansible Project\
**Created:** [August 3, 2021, 7:37am UTC](https://forum.ansible.com/t/ansible-module-to-read-log-file/35576 "2021-08-03T07:37:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![amitchettri](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/amitchettri/32/404_2.png) [@amitchettri](https://forum.ansible.com/u/amitchettri)\
**Post date:** [August 3, 2021, 7:37am UTC](https://forum.ansible.com/t/ansible-module-to-read-log-file/35576/1 "2021-08-03T07:37:18Z")

</div>

Hello All,

I am looking for a ansible module which can read **/var/log/messages**

I was using slurp but when the content of the **/var/log/messages** is quite long its not able to read the full content hence I made use of shell module like below

**shell: grep /var/log/messages**

but the ask is to find out the way to make use of module only. hence is there any module apart from slurp and shell which can read the file content and register it?

**NOTE: for lookup I was not able to read /var/log/messages with type as file and there is nothing as log available**

Regards  
AC

---

<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:** [August 3, 2021, 8:52am UTC](https://forum.ansible.com/t/ansible-module-to-read-log-file/35576/2 "2021-08-03T08:52:29Z")

</div>

Registering the entire /var/log/messages in a variable sounds like a bad idea.  
I see you are already grepping for strings?  
What is it that you are really looking for? What are you trying to accomplish?

---

<div class="post-metadata">

**Author:** ![amitchettri](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/amitchettri/32/404_2.png) [@amitchettri](https://forum.ansible.com/u/amitchettri)\
**Post date:** [August 3, 2021, 11:45pm UTC](https://forum.ansible.com/t/ansible-module-to-read-log-file/35576/3 "2021-08-03T23:45:38Z")

</div>

Hello Dick,

Task is to look for a particular keyword after a software has install and license is acquired in the log file /var/log/messages

Example: date xyz: license acquired

So currently I am using shell as below

Shell: grep xyz /var/log/message  
Register: output

And then doing assert to look for license acquired in output.stdout

Above works perfectly.

But I am looking for a way to achieve this using other module and not the shell module

Regards  
AC

---

<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:** [August 4, 2021, 7:58am UTC](https://forum.ansible.com/t/ansible-module-to-read-log-file/35576/4 "2021-08-04T07:58:53Z")

</div>

Is this some license key or something?  
Either way, if this software can only send it to the system log, then  
in this case shell+grep is probably the best option.

---

<div class="post-metadata">

**Author:** ![amitchettri](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/amitchettri/32/404_2.png) [@amitchettri](https://forum.ansible.com/u/amitchettri)\
**Post date:** [August 4, 2021, 8:36am UTC](https://forum.ansible.com/t/ansible-module-to-read-log-file/35576/5 "2021-08-04T08:36:00Z")

</div>

Yes,

I guess the same.

Regards  
AC
