Hi Bryan,
Here's what I get when I run the command
$ RAX_CREDS_FILE=.raxpub ansible web -i inventory/rax.py -m debug -a "msg={{ hostvars[groups['beta']|intersect(groups['db'])[0]]['db_port'] }}" --limit beta -v
beta_web1 | FAILED => Failed to template msg={{ hostvars[groups['beta']|intersect(groups['db'])[0]]['db_port'] }}: template error while templating string: expected token ',', got '['
$ RAX_CREDS_FILE=.raxpub ansible web -i inventory/rax.py -m debug -a "msg={{ hostvars[groups['beta']|intersect(groups['db'])[1]]['db_port'] }}" --limit beta -v
beta_web1 | FAILED => Failed to template msg={{ hostvars[groups['beta']|intersect(groups['db'])[1]]['db_port'] }}: template error while templating string: expected token ',', got '['
$ RAX_CREDS_FILE=.raxpub ansible web -i inventory/rax.py -m debug -a "msg={{ hostvars[groups['beta']|intersect(groups['db'])[2]]['db_port'] }}" --limit beta -v
beta_web1 | FAILED => Failed to template msg={{ hostvars[groups['beta']|intersect(groups['db'])[2]]['db_port'] }}: template error while templating string: expected token ',', got '['
notice the increment in the index but it still gets the same error.
If I omit the index to see what is there,
$ RAX_CREDS_FILE=.raxpub ansible web -i inventory/rax.py -m debug -a "msg={{ hostvars[groups['beta']|intersect(groups['db'])]['db_port'] }}" --limit beta -v
beta_web1 | FAILED => One or more undefined variables: ansible.runner.HostVars object has no element [u'beta_db1']
I'm not sure what I'm missing out here.