Hi,

I have an inventory file:
[dev]
dev_server1

[uat]
uat_server1

[prod]
prod_server1

variables file:
env_lists:
-  env_list: env_list1
   envs:
     - dev
     - uat
     - prod
-  env_list: env_list2
   envs:
     - prod
-  env_list: env_list3
   envs:
     - dev
     - prod

I'm trying to run a task on each env_list.  Eg
- hosts: env_list2*
  tasks:
  - include: a_task_that_will_run_on_prod_server1_only.yml

My best guess is to construct new groups using group_by:
- hosts: all
  tasks:
  group_by: key={{item.0.env_list}}_{{item.1}}
  with_subelements:
    - "{{ env_lists }}"
    - envs

- debug: var=group_names

This correctly outputs the right group names, eg:
env_list2_prod

But env_list2_prod contains all servers instead of just prod_server1.  In 
other words, when I run a task on hosts: env_list2*, it runs on all the 
servers.  I know I could use a Dynamic Inventory Script, but would be a 
fair amount of work.  Hoping there's a group_by way.  Any ideas?

Many thanks.

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8f1acf79-b0b9-4db3-a3e7-00f9fbe0e7a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to