Skip to content

Instantly share code, notes, and snippets.

@mikerowehl
Created June 26, 2015 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikerowehl/336ed466cc50d069f3f6 to your computer and use it in GitHub Desktop.
Save mikerowehl/336ed466cc50d069f3f6 to your computer and use it in GitHub Desktop.
Explicit loop with conditionals
- hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Get tag Name where exists
debug: msg="Host {{ item }} is tagged with {{ hostvars[item]['ec2_tag_Name'] }}"
with_items: groups.all
when: hostvars[item]['ec2_tag_Name'] is defined
- name: Output hosts without name
debug: msg="Host {{ item }} has no name tag"
with_items: groups.all
when: hostvars[item]['ec2_tag_Name'] is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment