Skip to content

Instantly share code, notes, and snippets.

Created March 16, 2015 20:09
Show Gist options
  • Save anonymous/6d7ddfedfbef434b2f54 to your computer and use it in GitHub Desktop.
Save anonymous/6d7ddfedfbef434b2f54 to your computer and use it in GitHub Desktop.
# Indexes
mongodb_indexes:
catalog: [
"db.serviceMetadata.createIndex({service: 1, objectId: 1},{background: true})",
"db.program.createIndex({title:1},{background : true})" ]
guid: [
"db.guids.createIndex({type:1},{background:true})",
"db.guids.createIndex({'data.peopleInfo.type':1,'data.peopleInfo.firstname':1},{background:true, sparse:true})" ]
tasks:
- name: Setup mongodb indexes
debug: msg="Key is {{ item.key }} with items {{ item.value }}"
with_dict: mongodb_indexes
@halberom
Copy link

# Indexes
mongodb_indexes:
  catalog: 
    sublist: 
      - "db.serviceMetadata.createIndex({service: 1, objectId: 1},{background: true})"
      - "db.program.createIndex({title:1},{background : true})" 
  guid: 
    sublist:
      - "db.guids.createIndex({type:1},{background:true})"
      - "db.guids.createIndex({'data.peopleInfo.type':1,'data.peopleInfo.firstname':1},{background:true, sparse:true})"

- dosomething: name={{ item.0 }} listitem={{ item.1 }}
  with_subelements:
    - mongodb_indexes
    - sublist

@halberom
Copy link

hmm, unfortunately the above didn't work, the item.0 only returned {}. instead, it needed this format

- hosts: foo
  vars:
    mongodb_indexes:
      - name: catalog
        sublist:
          - "db.serviceMetadata.createIndex({service: 1, objectId: 1},{background: true})"
          - "db.program.createIndex({title:1},{background : true})"
      - name: guid
        sublist:
          - "db.guids.createIndex({type:1},{background:true})"
          - "db.guids.createIndex({'data.peopleInfo.type':1,'data.peopleInfo.firstname':1},{background:true, sparse:true})"
  tasks:
     - debug: msg="name is {{ item.0.name }}, listitem is {{ item.1 }}"
       with_subelements:
         - mongodb_indexes
         - sublist

which is basically like a with_together, except the second list is nested. Not what i was expecting, and it's annoying it didn't allow just the key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment