# using tests to match a hostname

**URL:** <https://forum.ansible.com/t/using-tests-to-match-a-hostname/26201>\
**Category:** Ansible Project\
**Created:** [December 5, 2017, 12:07am UTC](https://forum.ansible.com/t/using-tests-to-match-a-hostname/26201 "2017-12-05T00:07:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke\_Miller](https://avatars.discourse-cdn.com/v4/letter/l/7feea3/32.png) [@Luke\_Miller](https://forum.ansible.com/u/Luke_Miller)\
**Post date:** [December 5, 2017, 12:07am UTC](https://forum.ansible.com/t/using-tests-to-match-a-hostname/26201/1 "2017-12-05T00:07:48Z")

</div>

I am trying to use tests to match a hostname, I want hostnames that end in the letter “d”, they are non-production hosts, here is what I have:

```auto
- name: Register to Foreman Redhat non-Prod
  redhat_subscription:
    state: present
    activationkey: "Non-Prod-Redhat-7"
    org_id: "Default_Organization"
  when: inventory_hostname_short | match("*d")

```

and I am getting this error:

TASK [Register to Foreman Redhat non-Prod] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [slpatch001d]: FAILED! =\> {“failed”: true, “msg”: “The conditional check ‘inventory\_hostname\_short | match("\*d")’ failed. The error was: nothing to repeat\n\nThe error appears to have been in ‘/Users/millerlu/misc/foreman.yml’: line 10, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Register to Foreman Redhat non-Prod\n ^ here\n”}

What am I doing wrong here?

Thanks,  
Luke

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [December 5, 2017, 1:14am UTC](https://forum.ansible.com/t/using-tests-to-match-a-hostname/26201/2 "2017-12-05T01:14:46Z")

</div>

The match is a regular expression match (not a wildcard match). If you want something ending in ‘d’ try this:

search(‘d$’)

kind regards  
Pshem
