How do I use status to assign variables

17 views
Skip to first unread message

Gilberto Valentin

unread,
Mar 14, 2016, 4:42:02 PM3/14/16
to Ansible Project
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.

Timothy Appnel

unread,
Mar 14, 2016, 5:17:34 PM3/14/16
to Ansible Project
You should have some form of inventory groups for development, testing and production.

Timothy Appnel
Principal Architect
Ansible by Red Hat

+1 718.404.6429 | ansible.com 

GitHub: tima

Twitter: @appnelgroup


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/333f046b-bdd3-48c8-919e-0b7037ebf3a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gilberto Valentin

unread,
Mar 14, 2016, 5:28:38 PM3/14/16
to Ansible Project
Do you mean in group_vars?

Timothy Appnel

unread,
Mar 14, 2016, 9:49:45 PM3/14/16
to Ansible Project
Essentially. Assign your hosts to a dev, test or prod group and set variables that apply to those groups. 

Timothy Appnel
Principal Architect
Ansible by Red Hat

+1 718.404.6429 | ansible.com 

GitHub: tima

Twitter: @appnelgroup


Reply all
Reply to author
Forward
0 new messages