# Custom module to get list of open linux ports and running services

**URL:** <https://forum.ansible.com/t/custom-module-to-get-list-of-open-linux-ports-and-running-services/27144>\
**Category:** Ansible Developer\
**Created:** [March 29, 2018, 5:22am UTC](https://forum.ansible.com/t/custom-module-to-get-list-of-open-linux-ports-and-running-services/27144 "2018-03-29T05:22:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akash\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@Akash\_Agarwal](https://forum.ansible.com/u/Akash_Agarwal)\
**Post date:** [March 29, 2018, 5:22am UTC](https://forum.ansible.com/t/custom-module-to-get-list-of-open-linux-ports-and-running-services/27144/1 "2018-03-29T05:22:53Z")

</div>

Hi All,

Is there a custom module/role already present to get list fo open ports and linux running services?  
If not, then I have to use command module. How do i parse the returned netstat output and conevert to a JSON document.

Thanks,  
Akash

---

<div class="post-metadata">

**Author:** ![sdoran](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@sdoran](https://forum.ansible.com/u/sdoran)\
**Post date:** [April 2, 2018, 4:42pm UTC](https://forum.ansible.com/t/custom-module-to-get-list-of-open-linux-ports-and-running-services/27144/2 "2018-04-02T16:42:34Z")

</div>

Akash,

There is a [service\_facts](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/system/service_facts.py) module that shipped in Ansible 2.5 that will list services. To get the open ports on a system, it would be much easier to write a custom facts module and parse the data rather than trying to parse the command output it in the playbook. You can use the run\_command method to get the output, then parse it in Python, and return the results in a dictionary via the exit\_json method.
