# Looking for an available port number

**URL:** <https://forum.ansible.com/t/looking-for-an-available-port-number/24168>\
**Category:** Ansible Project\
**Created:** [April 7, 2017, 6:37am UTC](https://forum.ansible.com/t/looking-for-an-available-port-number/24168 "2017-04-07T06:37:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew.leung](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrew.leung](https://forum.ansible.com/u/andrew.leung)\
**Post date:** [April 7, 2017, 6:37am UTC](https://forum.ansible.com/t/looking-for-an-available-port-number/24168/1 "2017-04-07T06:37:52Z")

</div>

Hi,

I am new to ansible and trying to test a playbook to check availability of a port number. If one found then use it, if not then go to the next one. Following is my playbook code,

tasks:

- name: check port number  
become: yes  
become\_user: root  
command: /bin/netstat -anp | grep “{{ item }}”  
register: result  
until: result.stdout.split()|length \> 0  
with\_sequence: start=5432 end=5500

Unfortunately it did not work and get me the following error.

TASK [check port number] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: unsupported operand type(s) for +: ‘NoneType’ and ‘int’  
fatal: [pmr71dev402.auiag.corp]: FAILED! =\> {“failed”: true, “msg”: “Unexpected failure during module execution.”, “stdout”: “”}

Could someone please help and advise?

Also, if there is a better way to do this please feel free to advise me too.

Regards,  
Andrew

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [April 7, 2017, 6:53pm UTC](https://forum.ansible.com/t/looking-for-an-available-port-number/24168/2 "2017-04-07T18:53:35Z")

</div>

Try using ‘shell’ instead of ‘command’ - since you are using | I think you are likely going to need shell, since | is a shell feature.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![andrew.leung](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrew.leung](https://forum.ansible.com/u/andrew.leung)\
**Post date:** [April 9, 2017, 11:37pm UTC](https://forum.ansible.com/t/looking-for-an-available-port-number/24168/3 "2017-04-09T23:37:07Z")

</div>

Hi Jon,

Thanks for your advice. I tried shell earlier and got the same error.

Please further advise if any.

Cheers,  
Andrew
