# How do I use status to assign variables

**URL:** <https://forum.ansible.com/t/how-do-i-use-status-to-assign-variables/20867>\
**Category:** Ansible Project\
**Created:** [March 14, 2016, 8:42pm UTC](https://forum.ansible.com/t/how-do-i-use-status-to-assign-variables/20867 "2016-03-14T20:42:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [March 14, 2016, 8:42pm UTC](https://forum.ansible.com/t/how-do-i-use-status-to-assign-variables/20867/1 "2016-03-14T20:42:02Z")

</div>

I have a couple of systems that follow a strict hostname schema. For example, depending on the environment, they all follow the same prefix for that environment:

- For development = dev-server1.domain.tld
- For testing = test-server1.domain.tld
- For production = prod-server1.domain.tld  
Using Ansible’s **setup** module, I know I can call the hostname with a variable of **facter\_hostname**. However, how do I use that variable value to compare it with a list of environments like the one above so that if the hostname has the prefix of **dev** , then assign a value of 1; if it contains a prefix of **test** , then assign it a value of 2; if it has a prefix of **prod** , then assign it a value of 3.

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel1](https://avatars.discourse-cdn.com/v4/letter/t/278dde/32.png) [@Timothy\_Appnel1](https://forum.ansible.com/u/Timothy_Appnel1)\
**Post date:** [March 14, 2016, 9:16pm UTC](https://forum.ansible.com/t/how-do-i-use-status-to-assign-variables/20867/2 "2016-03-14T21:16:45Z")

</div>

You should have some form of inventory groups for development, testing and production.

---

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [March 14, 2016, 9:28pm UTC](https://forum.ansible.com/t/how-do-i-use-status-to-assign-variables/20867/3 "2016-03-14T21:28:38Z")

</div>

Do you mean in group\_vars?

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel1](https://avatars.discourse-cdn.com/v4/letter/t/278dde/32.png) [@Timothy\_Appnel1](https://forum.ansible.com/u/Timothy_Appnel1)\
**Post date:** [March 15, 2016, 1:48am UTC](https://forum.ansible.com/t/how-do-i-use-status-to-assign-variables/20867/4 "2016-03-15T01:48:58Z")

</div>

Essentially. Assign your hosts to a dev, test or prod group and set variables that apply to those groups.
