Skip to content

Instantly share code, notes, and snippets.

@ytjohn
Created December 2, 2014 18:20
Show Gist options
  • Save ytjohn/263d5a4629c772177ca4 to your computer and use it in GitHub Desktop.
Save ytjohn/263d5a4629c772177ca4 to your computer and use it in GitHub Desktop.
iterate over a sub element

In inventory, have these defined

hostgroups: {
 'group1': [
    '1.1.1.1',
    '1.1.1.2.'
    '1.1.1.3'
    ],
 'group2': [
    '1.1.2.1',
    '1.1.3.1'
    ]
}

iterhosts: [1,2,3]
groups: ['group1', 'group2']

In task, have this defined:

  - name: Check if nodes are online
    test_tcp:
      host: "{{ hostgroups[item.0][item.1] }}"
      state: open
      port: 22
    with_nested:
      - groups
      - iterhosts
      
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment