I have 4 machines on rackspace - two sets of machines, for production and
beta. Each set has a web server and db server.
Here's what the metadata for each machine would look like

metadata: {
  group: web,
  set: production
}

metadata: {
  group: db,
  set: production
}

metadata: {
  group: web,
  set: beta
}

metadata: {
  group: db,
  set: beta
}

While deploying to machine set beta and group web, I need to get certain
variables from machine set beta and group db. I have been trying various
ways to ensure I get the right machine. I got a pointer from somebody on
IRC to try intersection filter to get the correct machine from the group.

So, I did this
  debug: var='groups['beta'] | intersection(groups['db'])'

The above gives me a string with machine name
"[u'beta_db1']"

I am unable to use it as shown in variables example
  debug: var='hostvars[{{ group['beta'] | intersection['groups['db'])
}}][0]]['db_port']

It returns the result as
"hostvars[[u'beta_db'][0]]['db_port']"

I intend to use this in my vars/main.yml as

app_db_port: <the variable defined for beta db machine>

Am I in the right direction? If so how to handle the issue where hostvars
needs a list but intersection returns a string? Or is there a better way to
achieve what I want?


-- 
With Regards,
Mehul Ved

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CADTL0oYm9Uziv4em%3DYgSxY7SR3MG72yUme%2BJmfy0Q8%3DsXCG2Zg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to