How do I use status to assign variables

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.

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

Do you mean in group_vars?

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