Skip to content

Instantly share code, notes, and snippets.

@jesselang
Created January 23, 2016 04:22
Show Gist options
  • Save jesselang/fecfb9647c8a3e92022f to your computer and use it in GitHub Desktop.
Save jesselang/fecfb9647c8a3e92022f to your computer and use it in GitHub Desktop.
Example ansible playbook to access facts from a group of hosts from another host
---
# Execute using ansible-playbook -i hosts example.yml
- hosts: web
gather_facts: yes
- hosts: db
gather_facts: no # optional; speed optimization
tasks:
- name: Display addresses of all web hosts
- debug: msg={{ hostvars[item].ansible_eth0.ipv4.address }}
with_items: groups['web']
[db]
localhost
# Put your database hosts here
[web]
localhost
# Put your web hosts here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment