Conditional Variables

Hi All,

I just started using Ansible and I’m in the process of writing my first playbook.

I’m trying to configure HAProxy and depending on where I’m creating the instance, Vagrant vs EC2 I want to use a different network interface. eth0 vs eth1

What is the best way to tackle this situation. I want to avoid creating conditionals in the template.

Should I use external_vars and have two separate playbooks?

Thanks,
Drew

I would probably consider something basic like passing in a “-e mode=vagrant” or “-e mode=ec2” on the playbook option line, and then doing

when: mode == ‘vagrant’

or

when: mode == ‘ec2’

or better yet, maybe defining this variable in your inventory file at group level.

Will something like that work, perhaps?

–Michael

Thanks Mike, those both sound like two good solutions.

For the time being I created two different playbook’s with var’s defined within. As I try to collapse the two playbooks I’ll try using variables within the inventory file

Drew